Class: Shomen::Model::AbstractPrime

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

Overview

Baseclass for all model classes.

Direct Known Subclasses

Abstract, Interface

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ AbstractPrime

Returns a new instance of AbstractPrime.



27
28
29
30
31
32
33
# File 'lib/shomen/model/abstract.rb', line 27

def initialize(settings={})
  @table = {}
  settings.each do |k,v|
    s = "#{k}=".gsub('-','_')
    __send__(s,v)
  end
end

Class Method Details

.attr_accessor(name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/shomen/model/abstract.rb', line 11

def self.attr_accessor(name)
  name = name.to_s
  define_method(name) do
    self[name]
  end
  define_method(name+'=') do |x|
    self[name] = x
  end
end

.typeObject



22
23
24
# File 'lib/shomen/model/abstract.rb', line 22

def self.type
  name.split('::').last.downcase
end

Instance Method Details

#[](k) ⇒ Object



36
37
38
# File 'lib/shomen/model/abstract.rb', line 36

def [](k)
  @table[k.to_s]
end

#[]=(k, v) ⇒ Object



41
42
43
# File 'lib/shomen/model/abstract.rb', line 41

def []=(k,v)
  @table[k.to_s] = v
end

#to_hObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/shomen/model/abstract.rb', line 46

def to_h
  t = {}
  @table.each do |k,v|
    if v.respond_to?(:to_h)
      t[k] = v.to_h
    else
      t[k] = v
    end
  end
  t
end