class AmazonOrder::Parser

Attributes

fetched_at[RW]

Public Class Methods

new(filepath, options = {}) click to toggle source
# File lib/amazon_order/parser.rb, line 5
def initialize(filepath, options = {})
  @filepath = filepath

  @fetched_at = if (m = File.basename(@filepath).match(/\D(\d{14})/))
    Time.strptime(m[1], '%Y%m%d%H%M%S')
  else
    File.ctime(@filepath)
  end
end

Public Instance Methods

body() click to toggle source
# File lib/amazon_order/parser.rb, line 23
def body
  @body ||= File.read(@filepath)
end
doc() click to toggle source
# File lib/amazon_order/parser.rb, line 19
def doc
  @doc ||= Nokogiri::HTML(body)
end
orders() click to toggle source
# File lib/amazon_order/parser.rb, line 15
def orders
  @orders ||= doc.css(".order").map{|e| AmazonOrder::Parsers::Order.new(e, fetched_at: fetched_at) }
end