Class: Navfund::Metrobank

Inherits:
Provider show all
Defined in:
lib/navfund/providers/metrobank.rb

Constant Summary collapse

MAIN_URL =

List of funds

"http://www.metrobank.com.ph/trust_product.asp"
Funds =
[
{:name => "Money Market Fund", :currency => "PHP", :type => "main"}, 
{:name => "Max-3 Bond Fund", :currency => "PHP", :type => "main"},
{:name => "Wealth Builder Fund", :currency => "PHP", :type => "main"},
{:name => "Max-5 Bond Fund", :currency => "PHP", :type => "main"},
{:name => "Balanced Fund", :currency => "PHP", :type => "main"},
{:name => "Equity Fund", :currency => "PHP", :type => "main"},
{:name => "$ Money Market Fund", :currency => "USD", :type => "main"},
{:name => "$ Max-3 Bond Fund", :currency => "USD", :type => "main"},
{:name => "$ Max-5 Bond Fund", :currency => "USD", :type => "main"}
]

Instance Method Summary collapse

Methods inherited from Provider

#scrape, strip_value

Constructor Details

#initializeMetrobank

Returns a new instance of Metrobank.



19
20
21
22
# File 'lib/navfund/providers/metrobank.rb', line 19

def initialize
  @url = MAIN_URL
  self.scrape
end

Instance Method Details

#fund_namesObject

List supported funds by name



49
50
51
# File 'lib/navfund/providers/metrobank.rb', line 49

def fund_names
  self.funds.map{ |x| x[:name] }
end

#fundsObject

List supported funds



44
45
46
# File 'lib/navfund/providers/metrobank.rb', line 44

def funds
  Funds
end

#valid_fund?(fund) ⇒ Boolean

Check if the fund name is supported

Returns:

  • (Boolean)


54
55
56
# File 'lib/navfund/providers/metrobank.rb', line 54

def valid_fund?(fund)
  self.fund_names.include?(fund)
end

#value(fund, fund_type = nil) ⇒ Object

Fetch the current value



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/navfund/providers/metrobank.rb', line 25

def value(fund, fund_type=nil)
  val = nil
  fund_type = fund_type.to_sym if fund_type.is_a?(String)
  # Set fund_type to nil if VUL page is not present
  fund_type = nil if fund_type == :vul && @wrapped_vul_document.nil?
  if valid_fund?(fund)
    source_document = (fund_type == :vul) ? @wrapped_vul_document : @wrapped_document
    fname = source_document.search("[text()*='#{fund}']").first
    if fname
      fval = fname.parent.next_element rescue nil
    end
    val = Provider.strip_value(fval.text) if fval
  else
    raise InvalidFund
  end
  val
end