Class: TableMe::TableVO

Inherits:
Object
  • Object
show all
Defined in:
lib/table_me/table_vo.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ TableVO

Returns a new instance of TableVO.



14
15
16
# File 'lib/table_me/table_vo.rb', line 14

def initialize params = {}
  self.merge! params
end

Class Method Details

.vo_attr_accessor(*args) ⇒ Object



5
6
7
8
# File 'lib/table_me/table_vo.rb', line 5

def self.vo_attr_accessor *args
  @@set_methods = *args
  attr_accessor *args
end

Instance Method Details

#[](key) ⇒ Object



22
23
24
# File 'lib/table_me/table_vo.rb', line 22

def [] key
  self.method(key).call
end

#[]=(key, value) ⇒ Object



18
19
20
# File 'lib/table_me/table_vo.rb', line 18

def []= key, value
  self.method("#{key}=").call(value)
end

#eachObject



33
34
35
36
37
# File 'lib/table_me/table_vo.rb', line 33

def each
  @@set_methods.each do |method|
    yield(method,self.method(method).call)
  end
end

#merge!(object) ⇒ Object



26
27
28
29
30
31
# File 'lib/table_me/table_vo.rb', line 26

def merge! object
  object.each do |k,v|
    self.method("#{k}=").call(v) unless v.nil?
  end
  self
end

#to_hashObject



39
40
41
42
43
44
45
# File 'lib/table_me/table_vo.rb', line 39

def to_hash
  hash = {}
  @@set_methods.each do |method|
    hash[method] = method(method).call
  end
  hash
end