Class: ItemPriceParser

Inherits:
Object
  • Object
show all
Defined in:
lib/discogs/wishlist/parsers/item_price_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(html, country) ⇒ ItemPriceParser

Returns a new instance of ItemPriceParser.



5
6
7
8
# File 'lib/discogs/wishlist/parsers/item_price_parser.rb', line 5

def initialize(html, country)
  @html = html
  @country = country
end

Instance Method Details

#parseObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/discogs/wishlist/parsers/item_price_parser.rb', line 10

def parse
  return [] unless rows.length.positive?

  rows.map do |row|
    price = row.search(".item_price .price").text.gsub(/[^\d.]+/, "")
    shipping = row.search(".item_shipping").first.text.gsub(/[^\d.]+/, "")

    return nil if price.nil? || shipping.nil?

    {
      price: Monetize.parse(price, country.currency.iso_code),
      shipping: Monetize.parse(shipping, country.currency.iso_code)
    }
  end.compact
end