class WeddingRegistryScraper::Registries::HeathCeramics
Private Instance Methods
get_desired(product)
click to toggle source
# File lib/wedding_registry_scraper/registries/heath_ceramics.rb, line 62 def get_desired(product) fulfillment = product.css('.fulfilled').text.strip fulfillment.match(/(\d+)$/)[0].to_i end
get_image_url(product)
click to toggle source
# File lib/wedding_registry_scraper/registries/heath_ceramics.rb, line 34 def get_image_url(product) details_url = product.css('[data-url]')[0]['data-url'] request_params = { :headers => { 'X-Requested-With' => 'XMLHttpRequest' } } result = with_lax_heath_uri_parsing do puts "GET #{details_url.inspect} with params #{request_params.to_json}" if @debug Unirest.get(details_url, request_params) end doc = Nokogiri::HTML(result.body) if doc.css('ul.mixMatchList').any? doc.css('ul.mixMatchList li:last-child img[src]')[0]['src'] else doc.css('.imagesScrollable img[src]')[0]['src'] end end
get_name(product)
click to toggle source
# File lib/wedding_registry_scraper/registries/heath_ceramics.rb, line 15 def get_name(product) product.css('.attentionText').text.strip end
get_price(product)
click to toggle source
# File lib/wedding_registry_scraper/registries/heath_ceramics.rb, line 67 def get_price(product) product.css('.price').text.strip.gsub(/[^\d\.]/, '').to_f end
get_products(doc)
click to toggle source
# File lib/wedding_registry_scraper/registries/heath_ceramics.rb, line 11 def get_products(doc) doc.css('table#shopping-cart-table tbody tr') end
get_remaining(product)
click to toggle source
# File lib/wedding_registry_scraper/registries/heath_ceramics.rb, line 57 def get_remaining(product) fulfillment = product.css('.fulfilled').text.strip fulfillment.match(/^(\d+)/)[0].to_i end
get_sku(product)
click to toggle source
# File lib/wedding_registry_scraper/registries/heath_ceramics.rb, line 19 def get_sku(product) text = product.css('.ctxProductCol .tinyText').map(&:text).detect { |t| t =~ /SKU/ } if text sku = text.match(/SKU:\s+(\S+)/)[1] "heath:#{sku}" else title = product.css('.ctxProductCol .attentionText').text.parameterize "heath:#{title}" end end
get_url(product)
click to toggle source
# File lib/wedding_registry_scraper/registries/heath_ceramics.rb, line 30 def get_url(product) @url end
split(uri)
click to toggle source
# File lib/wedding_registry_scraper/registries/heath_ceramics.rb, line 75 def split(uri) # scheme, userinfo, host, port, registry, path, opaque, query, fragment [ "http", nil, "www.heathceramics.com", nil, nil, uri.sub(/^https?:\/\/www.heathceramics.com/, ''), nil, nil, nil ] end
with_lax_heath_uri_parsing() { || ... }
click to toggle source
# File lib/wedding_registry_scraper/registries/heath_ceramics.rb, line 71 def with_lax_heath_uri_parsing(&block) URI::RFC3986_Parser.class_eval do alias_method :old_split, :split def split(uri) # scheme, userinfo, host, port, registry, path, opaque, query, fragment [ "http", nil, "www.heathceramics.com", nil, nil, uri.sub(/^https?:\/\/www.heathceramics.com/, ''), nil, nil, nil ] end end exception = nil begin result = yield rescue Exception => e exception = e ensure URI::RFC3986_Parser.class_eval do alias_method :split, :old_split end end raise exception if exception result end