Class: RZoopla::BaseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/zoopla/base_model.rb,
lib/rzoopla/base_model.rb

Direct Known Subclasses

Listing

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BaseModel

Returns a new instance of BaseModel.



3
4
5
6
7
8
9
10
11
# File 'lib/zoopla/base_model.rb', line 3

def initialize(options = {})
  self.class.attributes.each do |attribute|
    instance_variable_set("@#{attribute}", options[attribute])

    self.class.send(:define_method, attribute) do
      instance_variable_get("@#{attribute}")
    end
  end
end

Class Attribute Details

.attributesObject

Returns the value of attribute attributes.



20
21
22
# File 'lib/zoopla/base_model.rb', line 20

def attributes
  @attributes
end

Instance Method Details

#to_hashObject



13
14
15
16
17
# File 'lib/zoopla/base_model.rb', line 13

def to_hash
  Hash[*instance_variables.flat_map { |var|
    [var.to_s.delete('@'), instance_variable_get(var)]
  }]
end