Class: AmazonOrder::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon_order/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath, options = {}) ⇒ Parser

Returns a new instance of Parser.



5
6
7
8
9
10
11
12
13
# 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

Instance Attribute Details

#fetched_atObject

Returns the value of attribute fetched_at.



3
4
5
# File 'lib/amazon_order/parser.rb', line 3

def fetched_at
  @fetched_at
end

Instance Method Details

#bodyObject



23
24
25
# File 'lib/amazon_order/parser.rb', line 23

def body
  @body ||= File.read(@filepath)
end

#docObject



19
20
21
# File 'lib/amazon_order/parser.rb', line 19

def doc
  @doc ||= Nokogiri::HTML(body)
end

#ordersObject



15
16
17
# 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