class AmazonOrder::Parsers::Order

Constants

ATTRIBUTES

Public Instance Methods

all_products_displayed() click to toggle source

might be broken now that orders have multiple shipments

# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/amazon_order/parsers/order.rb, line 45
def products
  @products ||= shipment_products + digital_products
end
shipment_products() click to toggle source
# File lib/amazon_order/parsers/order.rb, line 49
def shipment_products
  @shipment_products ||= shipments.flat_map(&:products)
end
shipments() click to toggle source
# 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() click to toggle source
Calls superclass method AmazonOrder::Parsers::Base#to_hash
# File lib/amazon_order/parsers/order.rb, line 62
def to_hash
  super do |hash|
    hash.merge!(products: products.map(&:to_hash))
  end
end