Class: LeaflyApiWrapper::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/leafly_api_wrapper/mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path("../feed_mapper/#{feed_type}_mapper.json", __FILE__)
  @mapper = JSON.parse(File.read(path))
  @data   = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/leafly_api_wrapper/mapper.rb', line 6

def data
  @data
end

#mapperObject

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

#mappedObject



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