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



8
9
10
11
# File 'lib/leafly_api_wrapper/mapper.rb', line 8

def initialize(data, feed_type)
  @mapper = JSON.parse(File.read("./lib/leafly_api_wrapper/feed_mapper/#{feed_type}_mapper.json"))
  @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



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/leafly_api_wrapper/mapper.rb', line 13

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