Class: Pastvu::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/pastvu/model.rb

Direct Known Subclasses

Cluster, Comment, Photo

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Model

Returns a new instance of Model.



3
4
5
6
7
8
9
# File 'lib/pastvu/model.rb', line 3

def initialize(attributes)
  attributes.each do |key, value|
    key = snakecase(key)
    instance_variable_set("@#{key}", value)
    self.class.send(:attr_accessor, key)
  end
end

Instance Method Details

#to_hashObject



11
12
13
14
15
16
# File 'lib/pastvu/model.rb', line 11

def to_hash
  instance_variables.each_with_object({}) do |var, object|
    var = var[1..-1]
    object[camelize(var).to_sym] = method(var).call
  end
end

#to_jsonObject



18
19
20
# File 'lib/pastvu/model.rb', line 18

def to_json
  Parser.to_json(to_hash)
end