Class: AmazonOrder::Parser
- Inherits:
-
Object
- Object
- AmazonOrder::Parser
- Defined in:
- lib/amazon_order/parser.rb
Instance Attribute Summary collapse
-
#fetched_at ⇒ Object
Returns the value of attribute fetched_at.
Instance Method Summary collapse
- #body ⇒ Object
- #doc ⇒ Object
-
#initialize(filepath, options = {}) ⇒ Parser
constructor
A new instance of Parser.
- #orders ⇒ Object
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, = {}) @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_at ⇒ Object
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
#body ⇒ Object
23 24 25 |
# File 'lib/amazon_order/parser.rb', line 23 def body @body ||= File.read(@filepath) end |
#doc ⇒ Object
19 20 21 |
# File 'lib/amazon_order/parser.rb', line 19 def doc @doc ||= Nokogiri::HTML(body) end |
#orders ⇒ Object
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 |