Module: Magelex::MagentoCSV
- Defined in:
- lib/magelex/magento_csv.rb
Constant Summary collapse
- MONEY_FIELDS =
['Order Shipping', 'Order Grand Total', 'Item Total', 'Item Tax']
Class Method Summary collapse
-
.init_bill(row) ⇒ Object
Creates a bill with basic information from csv line.
- .parse(string) ⇒ Object
-
.read(filename) ⇒ Object
Reads file and returns lexware_bills.
Class Method Details
.init_bill(row) ⇒ Object
Creates a bill with basic information from csv line
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/magelex/magento_csv.rb', line 30 def self.init_bill row bill = Magelex::LexwareBill.new # TODO: defining a attribute|colum- map would be nicer bill.order_nr = row['Order Number'] bill.customer_name = row['Billing Name'] bill.country_code = row['Shipping Country'] bill.date = row['Order Date'] bill.status = row['Order Status'] bill.shipping_cost = row['Order Shipping'] bill.total = row['Order Grand Total'] bill end |
.parse(string) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/magelex/magento_csv.rb', line 46 def self.parse string bills = [] current_bill = Magelex::LexwareBill.new CSV::parse(string, :headers => :first_row, converters: [:all, :german_money_amount, :order_date]) do |row| # Multiple rows (with same order_nr) define one order # One order will be mapped to one bill if current_bill.order_nr != row['Order Number'] current_bill = init_bill row end current_bill.add_item(row['Item Total'], row['Item Tax'], row['Item Name']) if !bills.include? (current_bill) bills << current_bill end end bills end |
.read(filename) ⇒ Object
Reads file and returns lexware_bills
25 26 27 |
# File 'lib/magelex/magento_csv.rb', line 25 def self.read filename self.parse(File.read filename) end |