Class: Hashme::Property
- Inherits:
-
Object
- Object
- Hashme::Property
- Defined in:
- lib/hashme/property.rb
Instance Attribute Summary collapse
-
#array ⇒ Object
readonly
Returns the value of attribute array.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#build(owner, value) ⇒ Object
Build a new object of the type defined by the property.
-
#initialize(name, type, opts = {}) ⇒ Property
constructor
A new instance of Property.
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(name, type, opts = {}) ⇒ Property
Returns a new instance of Property.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/hashme/property.rb', line 6 def initialize(name, type, opts = {}) @name = name.to_sym # Always set type to base type if type.is_a?(Array) && !type.first.nil? @array = true @type = type.first else @array = false @type = type end # Handle options @default = opts[:default] end |
Instance Attribute Details
#array ⇒ Object (readonly)
Returns the value of attribute array.
4 5 6 |
# File 'lib/hashme/property.rb', line 4 def array @array end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
4 5 6 |
# File 'lib/hashme/property.rb', line 4 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/hashme/property.rb', line 4 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/hashme/property.rb', line 4 def type @type end |
Instance Method Details
#build(owner, value) ⇒ Object
Build a new object of the type defined by the property.
31 32 33 34 35 36 37 |
# File 'lib/hashme/property.rb', line 31 def build(owner, value) if array && value.is_a?(Array) CastedArray.new(self, owner, value) else PropertyCasting.cast(self, owner, value) end end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/hashme/property.rb', line 22 def to_s name.to_s end |
#to_sym ⇒ Object
26 27 28 |
# File 'lib/hashme/property.rb', line 26 def to_sym name end |