Class: ApmexPrice

Inherits:
Object
  • Object
show all
Defined in:
lib/apmex-price.rb

Constant Summary collapse

DOLLARS_REGEX =
/(\d*,*\d+\.\d+)/
BUY_CSS =
'div.page-content-main > div > div > strong'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ ApmexPrice

Returns a new instance of ApmexPrice.



10
11
12
13
# File 'lib/apmex-price.rb', line 10

def initialize(url)
	@url = url
	match()
end

Instance Attribute Details

#buyObject

Returns the value of attribute buy.



5
6
7
# File 'lib/apmex-price.rb', line 5

def buy
  @buy
end

#pageObject

Returns the value of attribute page.



5
6
7
# File 'lib/apmex-price.rb', line 5

def page
  @page
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/apmex-price.rb', line 5

def url
  @url
end

Instance Method Details

#matchObject



15
16
17
18
# File 'lib/apmex-price.rb', line 15

def match
	@page = Nokogiri::HTML(open(@url))
	@buy = match_dollars(BUY_CSS)
end

#match_dollars(dollars_css) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/apmex-price.rb', line 20

def match_dollars(dollars_css)
	dollars_text = @page.css(dollars_css).text
	dollars_match = DOLLARS_REGEX.match(dollars_text)

	if dollars_match != nil
		dollars_match[1].gsub(',', '').to_f
	else
		0.0
	end
end