Class: Nzbn::Models::Base
- Inherits:
-
Object
- Object
- Nzbn::Models::Base
- Defined in:
- lib/nzbn/models/base.rb
Overview
Base model class with common functionality
Direct Known Subclasses
Address, Company, EmailAddress, Entity, ErrorField, ErrorResponse, FullEntity, IndustryClassification, NonCompany, OrganisationPart, PhoneNumber, PrivacySettings, Role, RolePerson, SearchEntity, SearchResponse, TradingName, Watchlist, Website
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 |
# File 'lib/nzbn/models/base.rb', line 7 def initialize(attributes = {}) attributes.each do |key, value| setter = "#{underscore(key.to_s)}=" send(setter, value) if respond_to?(setter) end end |
Instance Method Details
#to_h ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/nzbn/models/base.rb', line 14 def to_h instance_variables.each_with_object({}) do |var, hash| key = var.to_s.delete('@') value = instance_variable_get(var) hash[key] = serialize_value(value) end end |
#to_json(*args) ⇒ Object
22 23 24 |
# File 'lib/nzbn/models/base.rb', line 22 def to_json(*args) to_h.to_json(*args) end |