Class: PricebrApple::PriceBR
- Inherits:
-
Object
- Object
- PricebrApple::PriceBR
- Defined in:
- lib/pricebr_apple.rb
Instance Method Summary collapse
- #get_last_price ⇒ Object
-
#get_list_partNumber(params) ⇒ Object
params : ‘http://’.
-
#get_price(params) ⇒ Object
params ‘device page’, partNumber: ‘model’.
-
#initialize ⇒ PriceBR
constructor
A new instance of PriceBR.
-
#script_crawler(params) ⇒ Object
params ‘text’, partNumber: ‘model’.
- #set_country(params) ⇒ Object
- #update_price ⇒ Object
Constructor Details
#initialize ⇒ PriceBR
Returns a new instance of PriceBR.
29 30 31 32 33 34 |
# File 'lib/pricebr_apple.rb', line 29 def initialize @model = nil @price = 0.0 @list_partNumber = [] @country = 'br' end |
Instance Method Details
#get_last_price ⇒ Object
61 62 63 |
# File 'lib/pricebr_apple.rb', line 61 def get_last_price @price end |
#get_list_partNumber(params) ⇒ Object
params : ‘http://’
72 73 74 75 76 77 78 |
# File 'lib/pricebr_apple.rb', line 72 def get_list_partNumber(params) unless params[:url_page].nil? @page = Nokogiri::HTML(open(params[:url_page])) @list_partNumber = @page.xpath("//meta[@itemprop='sku']/@content").map {|x| x.value} unless @page.nil? end @list_partNumber end |
#get_price(params) ⇒ Object
params ‘device page’, partNumber: ‘model’
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pricebr_apple.rb', line 44 def get_price(params) @model = params[:partNumber] url_page = params[:url_page] if !url_page.nil? && !@model.nil? @page = Nokogiri::HTML(open(url_page)) list_price = @page.css('.current_price') list_price = @page.css('.as-price-currentprice') if list_price.empty? unless list_price.nil? list_price.map{|item| @price = item.children[1].children[3].children[0].text.gsub(' ', '').gsub("\nR$",'').gsub("\n",'').gsub('.','').gsub(',','.').to_f if !item.nil? && item.children[1].children[1].values[1].to_s == @model} @price = self.script_crawler({script: list_price, partNumber: @model}) if @price.nil? else @price = 0.0 end end @price end |
#script_crawler(params) ⇒ Object
params ‘text’, partNumber: ‘model’
66 67 68 69 |
# File 'lib/pricebr_apple.rb', line 66 def script_crawler(params) if !params[:script].nil? && !params[:partNumber].nil? end end |
#set_country(params) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/pricebr_apple.rb', line 36 def set_country(params) unless params.nil? @country |= params @country = '' if @country.equal?('eua') end end |
#update_price ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/pricebr_apple.rb', line 80 def update_price list = [] PRICE_URL.each do |x,y| get_list_partNumber({url_page: y}) @list_partNumber.each do |part| self.get_price({url_page: y, partNumber: part}) list << [ part, self.get_last_price ] end end return list end |