Class: Oddb2xml::FirstbaseExtractor

Inherits:
Extractor
  • Object
show all
Defined in:
lib/oddb2xml/extractor.rb

Instance Attribute Summary

Attributes inherited from Extractor

#xml

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FirstbaseExtractor

Returns a new instance of FirstbaseExtractor.



610
611
612
# File 'lib/oddb2xml/extractor.rb', line 610

def initialize(file)
  @file = file
end

Instance Method Details

#to_hashObject



614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'lib/oddb2xml/extractor.rb', line 614

def to_hash
  data = {}
  return data unless @file && File.exist?(@file)
  CSV.foreach(@file, headers: true, encoding: "UTF-8") do |row|
    gtin = row["Gtin"].to_s.gsub(/^0+/, "")
    next if gtin.empty?
    data[gtin] = {
      gtin: gtin,
      gln: row["InformationProviderGln"].to_s,
      target_market: row["TargetMarketCountryCode"].to_s,
      gpc: row["GpcCategoryCode"].to_s,
      trade_item_description_de: row["TradeItemDescription_DE"].to_s,
      trade_item_description_en: "",
      trade_item_description_fr: row["TradeItemDescription_FR"].to_s,
      trade_item_description_it: row["TradeItemDescription_IT"].to_s,
      manufacturer_name: row["InformationProviderPartyName"].to_s,
      start_availability_date: row["Date_Created_Batch"].to_s,
      gross_weight: "",
      net_weight: "",
    }
  end
  data
end