Class: AmazonOrder::Parsers::Order
- Inherits:
-
Base
- Object
- Base
- AmazonOrder::Parsers::Order
show all
- Defined in:
- lib/amazon_order/parsers/order.rb
Constant Summary
collapse
- ATTRIBUTES =
%w[
order_placed order_number order_total
order_details_path
all_products_displayed
]
Instance Attribute Summary
Attributes inherited from Base
#fetched_at
Instance Method Summary
collapse
Methods inherited from Base
#get_original_image_url, #initialize, #inspect, #parse_date, #values
Instance Method Details
#all_products_displayed ⇒ Object
might be broken now that orders have multiple shipments
58
59
60
|
# File 'lib/amazon_order/parsers/order.rb', line 58
def all_products_displayed
@_all_products_displayed ||= @node.css('.a-box.order-info ~ .a-box .a-col-left .a-row').last.css('.a-link-emphasis').present?
end
|
#digital_products ⇒ Object
53
54
55
|
# File 'lib/amazon_order/parsers/order.rb', line 53
def digital_products
@_products ||= @node.css('.a-box:not(.shipment) .a-fixed-left-grid').map { |e| AmazonOrder::Parsers::Product.new(e, fetched_at: fetched_at) }
end
|
#order_details_path ⇒ Object
22
23
24
|
# File 'lib/amazon_order/parsers/order.rb', line 22
def order_details_path
@_order_details_path ||= @node.css('.order-info .a-col-right .a-row')[1].css('a.a-link-normal')[0].attr('href')
end
|
#order_number ⇒ Object
14
15
16
|
# File 'lib/amazon_order/parsers/order.rb', line 14
def order_number
@_order_number ||= @node.css('.order-info .a-col-right .a-row')[0].css('.value').text.strip
end
|
#order_placed ⇒ Object
10
11
12
|
# File 'lib/amazon_order/parsers/order.rb', line 10
def order_placed
@_order_placed ||= parse_date(@node.css('.order-info .a-col-left .a-column')[0].css('.value').text.strip)
end
|
#order_total ⇒ Object
18
19
20
|
# File 'lib/amazon_order/parsers/order.rb', line 18
def order_total
@_order_total ||= @node.css('.order-info .a-col-left .a-column')[1].css('.value').text.strip.gsub(/[^\d\.]/, '').to_f
end
|
#order_type ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/amazon_order/parsers/order.rb', line 26
def order_type
if @node.css('[id^=Leave-Service-Feedback]').present?
return :service_order
elsif @node.css('.shipment').present?
:shipment_order
else
:digital_order
end
end
|
#products ⇒ Object
45
46
47
|
# File 'lib/amazon_order/parsers/order.rb', line 45
def products
@products ||= shipment_products + digital_products
end
|
#shipment_products ⇒ Object
49
50
51
|
# File 'lib/amazon_order/parsers/order.rb', line 49
def shipment_products
@shipment_products ||= shipments.flat_map(&:products)
end
|
#shipments ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/amazon_order/parsers/order.rb', line 36
def shipments
@_shipments ||= @node.css('.shipment')
.map do |shipment|
AmazonOrder::Parsers::Shipment.new(shipment,
containing_object: self,
fetched_at: fetched_at)
end
end
|
#to_hash ⇒ Object
62
63
64
65
66
|
# File 'lib/amazon_order/parsers/order.rb', line 62
def to_hash
super do |hash|
hash.merge!(products: products.map(&:to_hash))
end
end
|