Class: Entity::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/entity_rb/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



3
4
5
6
7
# File 'lib/entity_rb/base.rb', line 3

def initialize(attributes={})
  attributes.each do |key, value|
    send("#{key}=", value) if fields.include? key.to_sym
  end
end

Class Method Details

.fieldsObject



19
20
21
# File 'lib/entity_rb/base.rb', line 19

def self.fields
  @fields
end

Instance Method Details

#attributesObject



9
10
11
12
13
14
15
16
17
# File 'lib/entity_rb/base.rb', line 9

def attributes
  hash = {}

  fields.each do |key|
    hash[key.to_sym] = self.send(key)
  end

  hash
end

#fieldsObject



23
24
25
# File 'lib/entity_rb/base.rb', line 23

def fields
  self.class.fields
end