Class: PartyResource::Property

Inherits:
Object
  • Object
show all
Includes:
Buildable
Defined in:
lib/party_resource/property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Buildable

#builder

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, options)
  @name = name
  @options = {:as => :raw}.merge(options || {})
end

Instance Attribute Details

#nameObject (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

Returns:

  • (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