Class: PartyResource::Property
- Inherits:
-
Object
- Object
- PartyResource::Property
- Includes:
- Buildable
- Defined in:
- lib/party_resource/property.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #has_value_in?(hash) ⇒ Boolean
-
#initialize(name, options) ⇒ Property
constructor
A new instance of Property.
- #to_hash(context) ⇒ Object
- #value_from(hash, context) ⇒ Object
Methods included from Buildable
Constructor Details
#initialize(name, options) ⇒ Property
Returns a new instance of Property.
8 9 10 11 |
# File 'lib/party_resource/property.rb', line 8 def initialize(name, ) @name = name @options = {:as => :raw}.merge( || {}) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/party_resource/property.rb', line 6 def name @name end |
Instance Method Details
#has_value_in?(hash) ⇒ Boolean
17 18 19 |
# File 'lib/party_resource/property.rb', line 17 def has_value_in?(hash) input_hash(hash).has_key?(input_key) || hash.has_key?(name) end |
#to_hash(context) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/party_resource/property.rb', line 21 def to_hash(context) value = context.send(name) return {} if value.nil? value = value.to_properties_hash if value.respond_to?(:to_properties_hash) output_keys.reverse.inject(value) do |value, key| {key => value} end end |
#value_from(hash, context) ⇒ Object
13 14 15 |
# File 'lib/party_resource/property.rb', line 13 def value_from(hash, context) builder.call retrieve_value(hash), context, {} end |