Sha256: 6285e0e68f4b4c94dfbc178bf9aa8b7fe1303102441445f9d4067ff1195e7674

Contents?: true

Size: 569 Bytes

Versions: 1

Compression:

Stored size: 569 Bytes

Contents

require 'csv'

module Dsfu
  class CsvProductFactory

    def initialize(csv_file)
      @csv = CSV.read(csv_file, headers: true)
    end

    def build
      products = []
      @csv.each do |product|
        products << Dsfu::Product.new(
          name: product['Display Name'],
          file_name: product['File Name'],
          display_name: product['Display Name'],
          height: product['Height'].to_f,
          width: product['Width'].to_f,
          price: product['Price'].scan(/[\d\.]+/)[0].to_f,
        )
      end
      products
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dsfu-0.0.1 lib/dsfu/csv_product_factory.rb