class Dech::Yahoo::CSV

Constants

ENCODING
HEADER_MAPPINGS
REQUIRED_HEADERS

Public Class Methods

new(products) click to toggle source
Calls superclass method Dech::CSV::new
# File lib/dech/yahoo/csv.rb, line 24
def initialize(products)
  @products = products
  super(formatted_products)
end

Public Instance Methods

valid?() click to toggle source
# File lib/dech/yahoo/csv.rb, line 29
def valid?
  validate! rescue false
end
validate!() click to toggle source
# File lib/dech/yahoo/csv.rb, line 33
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 Instance Methods

formatted_products() click to toggle source
# File lib/dech/yahoo/csv.rb, line 43
def formatted_products
  emmental = Emmental.new
  translated_products.each{|product| emmental << product }
  emmental.to_a
end
merged_products() click to toggle source
# File lib/dech/yahoo/csv.rb, line 53
def merged_products
  @products.map{|product| STATIC_COLUMNS.merge(product) }
end
translated_products() click to toggle source
# File lib/dech/yahoo/csv.rb, line 49
def translated_products
  merged_products.map{|product| Dech::HashKeyMapper.map(product, HEADER_MAPPINGS) }
end