Class: Navfund::Philamlife

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

Constant Summary collapse

MAIN_URL =
"https://portal.philamlife.com/NAVPU/philamlife"
VUL_URL =
"http://www.philamlife.com/en/individuals/resources-and-guides/fund-prices/pelac-variable-funds/pelac_variable_funds.html"
Funds =
[
{:name => "PAMI PHILAM BOND FUND", :currency => "PHP", :type => "main"}, 
{:name => "PAMI PHILAM FUND", :currency => "PHP", :type => "main"},
{:name => "PAMI PHILAM STRATEGIC GROWTH FUND", :currency => "PHP", :type => "main"},
{:name => "PESO FIXED INCOME FUND", :currency => "PHP", :type => "main"},
{:name => "PESO EQUITY FUND", :currency => "PHP", :type => "main"},
{:name => "PESO BALANCED FUND", :currency => "PHP", :type => "main"},
{:name => "DOLLAR BOND FUND", :currency => "USD", :type => "main"},
{:name => "DOLLAR GLOBAL BOND FUND", :currency => "USD", :type => "main"},
{:name => "DOLLAR HIGH-WATER MARK FUND 2019", :currency => "USD", :type => "main"},
{:name => "PRINCIPAL PROTECT FUND 1", :currency => "PHP", :type => "main"},
{:name => "PRINCIPAL PROTECT FUND 2", :currency => "PHP", :type => "main"},
{:name => "PRINCIPAL PROTECT EMERGING MARKETS FUND", :currency => "PHP", :type => "main"},
{:name => "ASIA'S BEST FUND 1", :currency => "PHP", :type => "main"},
{:name => "ASIA'S BEST FUND 2", :currency => "PHP", :type => "main"},
{:name => "GROWTH INVEST FUND 1", :currency => "PHP", :type => "main"},
{:name => "GROWTH INVEST FUND 2", :currency => "PHP", :type => "main"},
{:name => "GROWTH INVEST FUND 3", :currency => "PHP", :type => "main"},
{:name => "PELAC PESO EQUITY FUND", :currency => "PHP", :type => "vul"},
{:name => "PELAC PESO BALANCED FUND", :currency => "PHP", :type => "vul"},
{:name => "PELAC PESO FIXED INCOME FUND", :currency => "PHP", :type => "vul"},
{:name => "PELAC DOLLAR BOND FUND", :currency => "USD", :type => "vul"},
{:name => "PELAC GLOBAL BOND FUND", :currency => "PHP", :type => "vul"},
{:name => "PELAC DOLLAR HIGH-WATER MARK FUND 2019", :currency => "USD", :type => "vul"},
{:name => "PELAC PRINCIPAL PROTECT FUND 1", :currency => "PHP", :type => "vul"},
{:name => "PELAC PRINCIPAL PROTECT FUND 2", :currency => "PHP", :type => "vul"},
{:name => "PELAC PRINCIPAL PROTECT EMERGING MARKETS FUND", :currency => "PHP", :type => "vul"}
]

Instance Method Summary collapse

Methods inherited from Provider

#scrape, strip_value

Constructor Details

#initializePhilamlife

Returns a new instance of Philamlife.



37
38
39
40
41
# File 'lib/navfund/providers/philamlife.rb', line 37

def initialize
  @url = MAIN_URL
  @vul_url = VUL_URL
  self.scrape
end

Instance Method Details

#find_fund_node(doc, fund) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/navfund/providers/philamlife.rb', line 75

def find_fund_node(doc, fund)
  fname = nil
  if fund.match(/'/)
    # Fund name contains apostrophe, iterate nodeset and compare text instead
    tfund = fund.split('\'').last
    doc.search("[text()*='#{tfund}']").each do |tn|
      fname = tn if tn.text == fund
    end
  else
    fname = doc.search("[text()*='#{fund}']").first
  end
  fname
end

#fund_namesObject

List supported funds by name



95
96
97
# File 'lib/navfund/providers/philamlife.rb', line 95

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

#fundsObject

List supported funds



90
91
92
# File 'lib/navfund/providers/philamlife.rb', line 90

def funds
  Funds
end

#valid_fund?(fund) ⇒ Boolean

Check if the fund name is supported

Returns:

  • (Boolean)


100
101
102
# File 'lib/navfund/providers/philamlife.rb', line 100

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

#value(fund, fund_type = nil) ⇒ Object

Fetch the current value Some providers have a separate page for VUL funds, to force checking the VUL page, set the type to :vul, for example @sunlife.value(“Bond Fund”, :vul) It is possible that the same fund name is used for VUL and non-VUL funds so this is necessary



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/navfund/providers/philamlife.rb', line 47

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 = find_fund_node(source_document, fund)
    if fund_type == :vul
      fval = fname.next_element.next_element rescue nil
    else
      fval = fname.parent.next_element rescue nil
    end
    #fname = find_fund_node(source_document, fund)
    #if fname
    #  fval = fname.next_element.next_element rescue nil
    #elsif @wrapped_vul_document && fund_type != :vul
    #  # Search VUL page (if its not done before)
    #  fname = find_fund_node(@wrapped_vul_document, fund)
    #  fval = fname.next_element.next_element rescue nil
    #end
    val = Provider.strip_value(fval.text) if fval
  else
    raise InvalidFund
  end
  val
end