class Navfund::Provider
Attributes
funds[R]
Public Class Methods
strip_value(val)
click to toggle source
# File lib/navfund/provider.rb, line 16 def self.strip_value(val) val.strip.gsub('PHP', '').gsub('USD', '').gsub(',', '').strip end
Public Instance Methods
fund_names()
click to toggle source
List supported funds by name
# File lib/navfund/provider.rb, line 21 def fund_names funds.map{ |x| x[:name] } end
fund_values()
click to toggle source
Display all fund values
# File lib/navfund/provider.rb, line 41 def fund_values fvals = [] fund_names.each{ |f| fvals << { :name => f, :value => self.value(f) } } fvals end
scrape(opts={})
click to toggle source
# File lib/navfund/provider.rb, line 7 def scrape(opts={}) if opts[:check_ssl] == false @document = open(@url, :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read else @document = open(@url).read end @wrapped_document = Nokogiri::HTML(@document) end
uitf_com_ph_date_parser()
click to toggle source
# File lib/navfund/provider.rb, line 62 def uitf_com_ph_date_parser dtext = @wrapped_document.search("h5").first.text dstr = dtext.split("as of").last.strip Date.parse(dstr) end
uitf_com_ph_parser(fund)
click to toggle source
Generic parser for uitf.com.ph website
# File lib/navfund/provider.rb, line 48 def uitf_com_ph_parser(fund) val = nil if valid_fund?(fund) fname = @wrapped_document.search("[text()*='#{fund}']").first if fname fval = fname.ancestors('tr').first.search("td[data-title='NAVpu'] div").first rescue nil end val = Provider.strip_value(fval.text).to_f if fval else raise InvalidFund end val end
valid_fund?(fund)
click to toggle source
Check if the fund name is supported
# File lib/navfund/provider.rb, line 26 def valid_fund?(fund) fund_names.include?(fund) end
value()
click to toggle source
Returns the fund value
# File lib/navfund/provider.rb, line 31 def value nil end
value_at()
click to toggle source
Returns the date of the fund values
# File lib/navfund/provider.rb, line 36 def value_at nil end