Sha256: e6b4a4ea1a5fb020a7bd45a868f2963c243ca9c08205bfbc7061c2dbdc695a5d

Contents?: true

Size: 776 Bytes

Versions: 6

Compression:

Stored size: 776 Bytes

Contents

module AmazonOrder
  module Parsers
    class Product < Base
      ATTRIBUTES = %w[
                     title
                     path
                     content
                     image_url
                   ]

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

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

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

      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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
amazon_order-0.3.0 lib/amazon_order/parsers/product.rb
amazon_order-0.2.1 lib/amazon_order/parsers/product.rb
amazon_order-0.2.0 lib/amazon_order/parsers/product.rb
amazon_order-0.1.6 lib/amazon_order/parsers/product.rb
amazon_order-0.1.5 lib/amazon_order/parsers/product.rb
amazon_order-0.1.4 lib/amazon_order/parsers/product.rb