Sha256: 529069f4a3413145e24f6f4d1ace1afce80473d62cf5d590ceec06edd929e3b9
Contents?: true
Size: 1.19 KB
Versions: 5
Compression:
Stored size: 1.19 KB
Contents
# coding: utf-8 require 'emmental' require 'dech/csv' require 'dech/hash_key_mapper' module Dech class Yahoo class CSV < Dech::CSV ENCODING = Encoding::Windows_31J HEADER_MAPPINGS = { id: "code", price: ["price", "sale-price"] } REQUIRED_HEADERS = [ "path", "name", "code", "price", "sale-price" ] def initialize(products) @products = products super(formatted_products) end def valid? validate! rescue false end def validate! translated_products.each do |product| REQUIRED_HEADERS.each do |header| raise "#{header} is missing in #{product}" unless product.keys.include?(header) end end end private def formatted_products emmental = Emmental.new translated_products.each{|product| emmental << product } emmental.to_a end def translated_products merged_products.map{|product| Dech::HashKeyMapper.map(product, HEADER_MAPPINGS) } end def merged_products @products.map{|product| STATIC_COLUMNS.merge(product) } end end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
dech-0.1.1 | lib/dech/yahoo/csv.rb |
dech-0.1.0 | lib/dech/yahoo/csv.rb |
dech-0.0.7 | lib/dech/yahoo/csv.rb |
dech-0.0.6 | lib/dech/yahoo/csv.rb |
dech-0.0.5 | lib/dech/yahoo/csv.rb |