Class: Moo::Model::Side
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#pack ⇒ Object
Returns the value of attribute pack.
-
#side_num ⇒ Object
Returns the value of attribute side_num.
-
#template ⇒ Object
Returns the value of attribute template.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #data_from_hash(hash) ⇒ Object
- #from_hash(hash) ⇒ Object
- #from_json(json) ⇒ Object
-
#initialize {|_self| ... } ⇒ Side
constructor
A new instance of Side.
- #template_code ⇒ Object
-
#template_code=(code) ⇒ Object
wrapper that sets template object.
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Side
Returns a new instance of Side.
7 8 9 10 |
# File 'lib/moo/model/side.rb', line 7 def initialize @data = [] yield self if block_given? end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/moo/model/side.rb', line 5 def data @data end |
#pack ⇒ Object
Returns the value of attribute pack.
5 6 7 |
# File 'lib/moo/model/side.rb', line 5 def pack @pack end |
#side_num ⇒ Object
Returns the value of attribute side_num.
5 6 7 |
# File 'lib/moo/model/side.rb', line 5 def side_num @side_num end |
#template ⇒ Object
Returns the value of attribute template.
5 6 7 |
# File 'lib/moo/model/side.rb', line 5 def template @template end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/moo/model/side.rb', line 5 def type @type end |
Instance Method Details
#data_from_hash(hash) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/moo/model/side.rb', line 63 def data_from_hash(hash) klass = hash[:type].gsub(/\b\w/){|s|s.upcase} data = eval(klass).new data.from_hash hash data end |
#from_hash(hash) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/moo/model/side.rb', line 56 def from_hash hash self.side_num = hash[:sideNum] self.template_code = hash[:templateCode] self.type = hash[:type] self.data = hash[:data].map {|d| data_from_hash d } end |
#from_json(json) ⇒ Object
52 53 54 |
# File 'lib/moo/model/side.rb', line 52 def from_json json from_hash(JSON.parse(json, :symbolize_names => true)) end |
#template_code ⇒ Object
34 35 36 37 |
# File 'lib/moo/model/side.rb', line 34 def template_code return nil if @template.nil? @template.code end |
#template_code=(code) ⇒ Object
wrapper that sets template object
27 28 29 30 31 32 |
# File 'lib/moo/model/side.rb', line 27 def template_code=code unless Template.codes.include? code raise ArgumentError, "invalid templatecode" end @template = Template.with_code code end |
#to_hash ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/moo/model/side.rb', line 43 def to_hash hash = { sideNum: side_num, templateCode: template_code, type: type, data: data.map { |d| d.to_hash } } end |
#to_json ⇒ Object
39 40 41 |
# File 'lib/moo/model/side.rb', line 39 def to_json to_hash.to_json end |