Class: Trader::WebConverter

Inherits:
SyncConverter show all
Defined in:
lib/trade-o-matic/converters/web_converter.rb

Instance Attribute Summary collapse

Attributes inherited from SyncConverter

#ttl

Attributes inherited from FixedConverter

#rate

Instance Method Summary collapse

Methods inherited from SyncConverter

#expired?, #rate

Methods inherited from FixedConverter

#apply, #current_rate

Methods inherited from Converter

#apply, #current_rate

Constructor Details

#initialize(_url, _path, _ttl = 30) ⇒ WebConverter

Returns a new instance of WebConverter.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/trade-o-matic/converters/web_converter.rb', line 7

def initialize(_url, _path, _ttl=30)
  @url = _url
  @path = _path

  super(_ttl) do
    pincers = Pincers.for_chenso
    pincers.goto _url
    el = pincers.search(_path).first
    raise "No element found at #{_path}" if el.nil?
    Standard.amount el.text.gsub(/[^\d\s\.\,]+/,'').strip
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/trade-o-matic/converters/web_converter.rb', line 5

def path
  @path
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/trade-o-matic/converters/web_converter.rb', line 5

def url
  @url
end