Class: AmazonOrder::Parsers::Product

Inherits:
Base
  • Object
show all
Defined in:
lib/amazon_order/parsers/product.rb

Constant Summary collapse

ATTRIBUTES =
%w[
  title
  path
  content
  image_url
]

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, #to_hash, #values

Constructor Details

This class inherits a constructor from AmazonOrder::Parsers::Base

Instance Method Details

#contentObject



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

def content
  @_content ||= @node.css('.a-col-right .a-row')[1..-1].map(&:text).join.gsub(/\s+/, ' ').strip
end

#image_urlObject



23
24
25
26
27
28
# File 'lib/amazon_order/parsers/product.rb', line 23

def image_url
  @_image_url ||= begin
    img = @node.css('.a-col-left img')[0]
    get_original_image_url(img.attr('data-a-hires').presence || img.attr('src'))
  end
end

#pathObject



15
16
17
# File 'lib/amazon_order/parsers/product.rb', line 15

def path
  @_path ||= @node.css('.a-col-right .a-row a')[0].attr('href') rescue nil
end

#titleObject



11
12
13
# File 'lib/amazon_order/parsers/product.rb', line 11

def title
  @_title ||= @node.css('.a-col-right .a-row')[0].text.strip
end