Class: DaisybillApi::Ext::Attributes::Attribute
- Inherits:
-
Object
- Object
- DaisybillApi::Ext::Attributes::Attribute
- Defined in:
- lib/daisybill_api/ext/attributes/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(name, type, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #param_name ⇒ Object
- #param_value ⇒ Object
- #readonly? ⇒ Boolean
- #to_param ⇒ Object
Constructor Details
#initialize(name, type, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
9 10 11 12 13 14 |
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 9 def initialize(name, type, = {}) @name = name.to_s @type = type @options = @value = [] if collection? end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 6 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 6 def @options end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 6 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
7 8 9 |
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 7 def value @value end |
Instance Method Details
#param_name ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 24 def param_name if collection? simple_collection? ? name : "#{name}_attributes" else simple_type? ? name : "#{name}_attributes" end end |
#param_value ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 32 def param_value if collection? simple_collection? ? value : value.map(&:to_params) else simple_type? ? value : (value && value.to_params) end end |
#readonly? ⇒ Boolean
20 21 22 |
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 20 def readonly? !![:readonly] end |
#to_param ⇒ Object
40 41 42 |
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 40 def to_param readonly? ? {} : { param_name => param_value } end |