class AmazonPurchasesLedger::Item
Public Class Methods
new(items_csv_row:)
click to toggle source
# File lib/amazon_purchases_ledger/item.rb, line 3 def initialize(items_csv_row:) @items_csv_row = items_csv_row end
Public Instance Methods
item_quantity_string()
click to toggle source
# File lib/amazon_purchases_ledger/item.rb, line 16 def item_quantity_string "#{@items_csv_row[:quantity]}x " if @items_csv_row[:quantity] end
output_text()
click to toggle source
# File lib/amazon_purchases_ledger/item.rb, line 7 def output_text [ '* ', item_cost, ' for ', item_quantity_string, item_title, ', ', 'Seller: ', item_seller ].join end
Private Instance Methods
item_cost()
click to toggle source
# File lib/amazon_purchases_ledger/item.rb, line 29 def item_cost @items_csv_row[:item_total] end
item_seller()
click to toggle source
# File lib/amazon_purchases_ledger/item.rb, line 21 def item_seller @items_csv_row[:seller] end
item_title()
click to toggle source
# File lib/amazon_purchases_ledger/item.rb, line 25 def item_title truncate(@items_csv_row[:title], 40) end
truncate(content, max)
click to toggle source
# File lib/amazon_purchases_ledger/item.rb, line 33 def truncate(content, max) if content.length > max truncated = "" collector = "" content = content.split(" ") content.each do |word| word = word + " " collector << word truncated << word if collector.length < max end truncated = truncated.strip.chomp(",").concat("...") else truncated = content end return truncated end