Class: AmazonOrder::Writer
- Inherits:
-
Object
- Object
- AmazonOrder::Writer
- Defined in:
- lib/amazon_order/writer.rb
Instance Method Summary collapse
- #generate_csv ⇒ Object
-
#initialize(file_glob_pattern, options = {}) ⇒ Writer
constructor
A new instance of Writer.
- #print_orders ⇒ Object
- #print_products ⇒ Object
Constructor Details
#initialize(file_glob_pattern, options = {}) ⇒ Writer
Returns a new instance of Writer.
3 4 5 6 |
# File 'lib/amazon_order/writer.rb', line 3 def initialize(file_glob_pattern, = {}) @file_glob_pattern = file_glob_pattern @output_dir = .fetch(:output_dir, 'tmp') end |
Instance Method Details
#generate_csv ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/amazon_order/writer.rb', line 16 def generate_csv require 'csv' FileUtils.mkdir_p(@output_dir) %w[orders products].map do |resource| next if data[resource].blank? csv_file = "#{@output_dir}/#{resource}#{Time.current.strftime('%Y%m%d%H%M%S')}.csv" puts " Writing #{csv_file}" CSV.open(csv_file, 'wb') do |csv| csv << attributes_for(resource) data[resource].each { |r| csv << r } end csv_file end end |
#print_orders ⇒ Object
8 9 10 |
# File 'lib/amazon_order/writer.rb', line 8 def print_orders data['orders'] end |
#print_products ⇒ Object
12 13 14 |
# File 'lib/amazon_order/writer.rb', line 12 def print_products data['products'] end |