Class: EndecaOnDemand::Response::RecordsSet::Record

Inherits:
Proxy
  • Object
show all
Includes:
PP
Defined in:
lib/endeca_on_demand/response/records_set/record.rb

Instance Attribute Summary collapse

Attributes inherited from Proxy

#xml

Instance Method Summary collapse

Methods included from PP

#inspect, #pretty_print

Methods inherited from Proxy

#inspect

Constructor Details

#initialize(records_set, xml) ⇒ Record

Returns a new instance of Record.



14
15
16
17
18
# File 'lib/endeca_on_demand/response/records_set/record.rb', line 14

def initialize(records_set, xml)
  @records_set, @xml = records_set, xml

  define_getters(:serializable_hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (protected)



55
56
57
58
59
# File 'lib/endeca_on_demand/response/records_set/record.rb', line 55

def method_missing(method, *args, &block)
  super(method, *args, &block)
rescue NoMethodError
  ''
end

Instance Attribute Details

#propertiesObject (readonly)

associations ##



12
13
14
# File 'lib/endeca_on_demand/response/records_set/record.rb', line 12

def properties
  @properties
end

#records_setObject (readonly)

fields ##



12
13
14
# File 'lib/endeca_on_demand/response/records_set/record.rb', line 12

def records_set
  @records_set
end

Instance Method Details

#classObject

override proxy ##



22
23
24
# File 'lib/endeca_on_demand/response/records_set/record.rb', line 22

def class
  EndecaOnDemand::Response::RecordsSet::Record
end

#inspect_attributesObject



8
# File 'lib/endeca_on_demand/response/records_set/record.rb', line 8

def inspect_attributes; [ :properties ]; end

#keysObject

data ##



38
39
40
# File 'lib/endeca_on_demand/response/records_set/record.rb', line 38

def keys
  properties.map { |property| property.name }
end

#serializable_hashObject Also known as: to_hash



42
43
44
45
46
47
48
# File 'lib/endeca_on_demand/response/records_set/record.rb', line 42

def serializable_hash
  properties.inject({}) do |hash,property|
    hash.tap do
      hash.has_key?(property.label) ? (hash[property.label] = [*hash[property.label]].push(property.value)) : (hash[property.label] = property.value)
    end
  end.symbolize_keys
end