Class: ApmexPrice
- Inherits:
-
Object
- Object
- ApmexPrice
- 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
-
#buy ⇒ Object
Returns the value of attribute buy.
-
#page ⇒ Object
Returns the value of attribute page.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url) ⇒ ApmexPrice
constructor
A new instance of ApmexPrice.
- #match ⇒ Object
- #match_dollars(dollars_css) ⇒ Object
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
#buy ⇒ Object
Returns the value of attribute buy.
5 6 7 |
# File 'lib/apmex-price.rb', line 5 def buy @buy end |
#page ⇒ Object
Returns the value of attribute page.
5 6 7 |
# File 'lib/apmex-price.rb', line 5 def page @page end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/apmex-price.rb', line 5 def url @url end |
Instance Method Details
#match ⇒ Object
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 |