Class: LeaflyApiWrapper::Mapper
- Inherits:
-
Object
- Object
- LeaflyApiWrapper::Mapper
- Defined in:
- lib/leafly_api_wrapper/mapper.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#mapper ⇒ Object
Returns the value of attribute mapper.
Instance Method Summary collapse
-
#initialize(data, feed_type) ⇒ Mapper
constructor
A new instance of Mapper.
- #mapped ⇒ Object
Constructor Details
#initialize(data, feed_type) ⇒ Mapper
Returns a new instance of Mapper.
8 9 10 11 12 |
# File 'lib/leafly_api_wrapper/mapper.rb', line 8 def initialize(data, feed_type) path = File.("../feed_mapper/#{feed_type}_mapper.json", __FILE__) @mapper = JSON.parse(File.read(path)) @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/leafly_api_wrapper/mapper.rb', line 6 def data @data end |
#mapper ⇒ Object
Returns the value of attribute mapper.
6 7 8 |
# File 'lib/leafly_api_wrapper/mapper.rb', line 6 def mapper @mapper end |
Instance Method Details
#mapped ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/leafly_api_wrapper/mapper.rb', line 14 def mapped res = {} @mapper.each_pair do |k,v| if v.is_a? Array res[k] = v.map{ |cv| @data[cv] }.join(' ').strip elsif res[k] = @data[v] end end res end |