Class: Marbu::Models::Base
- Inherits:
-
Object
- Object
- Marbu::Models::Base
- Defined in:
- lib/marbu/models/mrf/base.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#keys ⇒ Object
Returns the value of attribute keys.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #add_key(name, function = nil) ⇒ Object
- #add_value(name, function = nil) ⇒ Object
- #blank? ⇒ Boolean
- #default_options ⇒ Object
-
#initialize(ext_options = {}) ⇒ Base
constructor
A new instance of Base.
- #present? ⇒ Boolean
- #serializable_hash ⇒ Object
Constructor Details
#initialize(ext_options = {}) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 13 14 |
# File 'lib/marbu/models/mrf/base.rb', line 7 def initialize( = {}) # keep_if weeds out nil arguments = .merge( .keep_if{|k,v| v} ) @keys = [:keys].map{ |k| Key.new(k) } @values = [:values].map{ |v| Value.new(v) } self.code = [:code] end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
5 6 7 |
# File 'lib/marbu/models/mrf/base.rb', line 5 def code @code end |
#keys ⇒ Object
Returns the value of attribute keys.
4 5 6 |
# File 'lib/marbu/models/mrf/base.rb', line 4 def keys @keys end |
#values ⇒ Object
Returns the value of attribute values.
4 5 6 |
# File 'lib/marbu/models/mrf/base.rb', line 4 def values @values end |
Instance Method Details
#add_key(name, function = nil) ⇒ Object
42 43 44 |
# File 'lib/marbu/models/mrf/base.rb', line 42 def add_key(name, function = nil) add(:key, name, function) end |
#add_value(name, function = nil) ⇒ Object
46 47 48 |
# File 'lib/marbu/models/mrf/base.rb', line 46 def add_value(name, function = nil) add(:value, name, function) end |
#blank? ⇒ Boolean
54 55 56 |
# File 'lib/marbu/models/mrf/base.rb', line 54 def blank? !present? end |
#default_options ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/marbu/models/mrf/base.rb', line 16 def { :keys => [], :values => [], :code => Code.new } end |
#present? ⇒ Boolean
50 51 52 |
# File 'lib/marbu/models/mrf/base.rb', line 50 def present? @keys.present? || code.present? end |
#serializable_hash ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/marbu/models/mrf/base.rb', line 34 def serializable_hash { :keys => keys.collect(&:serializable_hash), :values => values.collect(&:serializable_hash), :code => code.serializable_hash }.delete_if{|k,v|v.blank?} end |