navfund 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/navfund.rb CHANGED
@@ -17,7 +17,8 @@ require "navfund/provider"
17
17
  # Providers
18
18
  require "navfund/providers/metrobank"
19
19
  require "navfund/providers/sunlife"
20
+ require "navfund/providers/philamlife"
20
21
 
21
22
  module Navfund
22
- Providers = [Metrobank, Sunlife]
23
+ Providers = [Metrobank, Sunlife, Philamlife]
23
24
  end
@@ -0,0 +1,96 @@
1
+ # Philam Life
2
+
3
+ module Navfund
4
+ class Philamlife < Provider
5
+ MAIN_URL = "http://www.philamlife.com/en/individuals/resources-and-guides/fund-prices/philam-life-variable-funds/philam_life_variable_funds.html"
6
+ VUL_URL = "http://www.philamlife.com/en/individuals/resources-and-guides/fund-prices/pelac-variable-funds/pelac_variable_funds.html"
7
+ Funds = [
8
+ {:name => "PAMI PHILAM BOND FUND", :currency => "PHP"},
9
+ {:name => "PAMI PHILAM FUND", :currency => "PHP"},
10
+ {:name => "PAMI PHILAM STRATEGIC GROWTH FUND", :currency => "PHP"},
11
+ {:name => "PESO FIXED INCOME FUND", :currency => "PHP"},
12
+ {:name => "PESO EQUITY FUND", :currency => "PHP"},
13
+ {:name => "PESO BALANCED FUND", :currency => "PHP"},
14
+ {:name => "DOLLAR BOND FUND", :currency => "USD"},
15
+ {:name => "DOLLAR GLOBAL BOND FUND", :currency => "USD"},
16
+ {:name => "DOLLAR HIGH-WATER MARK FUND", :currency => "USD"},
17
+ {:name => "PRINCIPAL PROTECT FUND 1", :currency => "PHP"},
18
+ {:name => "PRINCIPAL PROTECT FUND 2", :currency => "PHP"},
19
+ {:name => "PRINCIPAL PROTECT EMERGING MARKETS FUND", :currency => "PHP"},
20
+ {:name => "ASIA'S BEST FUND 1", :currency => "PHP"},
21
+ {:name => "ASIA'S BEST FUND 2", :currency => "PHP"},
22
+ {:name => "GROWTH INVEST FUND 1", :currency => "PHP"},
23
+ {:name => "GROWTH INVEST FUND 2", :currency => "PHP"},
24
+ {:name => "GROWTH INVEST FUND 3", :currency => "PHP"},
25
+ {:name => "PELAC PESO EQUITY FUND", :currency => "PHP"},
26
+ {:name => "PELAC PESO BALANCED FUND", :currency => "PHP"},
27
+ {:name => "PELAC PESO FIXED INCOME FUND", :currency => "PHP"},
28
+ {:name => "PELAC DOLLAR BOND FUND", :currency => "USD"},
29
+ {:name => "PELAC GLOBAL BOND FUND", :currency => "PHP"},
30
+ {:name => "PELAC DOLLAR HIGH-WATER MARK FUND", :currency => "USD"},
31
+ {:name => "PELAC PRINCIPAL PROTECT FUND", :currency => "PHP"},
32
+ {:name => "PELAC PRINCIPAL PROTECT FUND", :currency => "PHP"},
33
+ {:name => "PELAC PRINCIPAL PROTECT EMERGING MARKETS FUND", :currency => "PHP"}
34
+ ]
35
+
36
+ def initialize
37
+ @url = MAIN_URL
38
+ @vul_url = VUL_URL
39
+ self.scrape
40
+ end
41
+
42
+ # Fetch the current value
43
+ # Some providers have a separate page for VUL funds, to force checking the VUL page,
44
+ # set the type to :vul, for example @sunlife.value("Bond Fund", :vul)
45
+ # It is possible that the same fund name is used for VUL and non-VUL funds so this is necessary
46
+ def value(fund, fund_type=nil)
47
+ val = nil
48
+ # Set fund_type to nil if VUL page is not present
49
+ fund_type = nil if fund_type == :vul && @wrapped_vul_document.nil?
50
+ if valid_fund?(fund)
51
+ source_document = (fund_type == :vul) ? @wrapped_vul_document : @wrapped_document
52
+ fname = find_fund_node(source_document, fund)
53
+ if fname
54
+ fval = fname.next_element.next_element rescue nil
55
+ elsif @wrapped_vul_document && fund_type != :vul
56
+ # Search VUL page (if its not done before)
57
+ fname = find_fund_node(@wrapped_vul_document, fund)
58
+ fval = fname.next_element.next_element rescue nil
59
+ end
60
+ val = Provider.strip_value(fval.text) if fval
61
+ else
62
+ raise InvalidFund
63
+ end
64
+ val
65
+ end
66
+
67
+ def find_fund_node(doc, fund)
68
+ fname = nil
69
+ if fund.match(/'/)
70
+ # Fund name contains apostrophe, iterate nodeset and compare text instead
71
+ tfund = fund.split('\'').last
72
+ doc.search("[text()*='#{tfund}']").each do |tn|
73
+ fname = tn if tn.text == fund
74
+ end
75
+ else
76
+ fname = doc.search("[text()*='#{fund}']").first
77
+ end
78
+ fname
79
+ end
80
+
81
+ # List supported funds
82
+ def funds
83
+ Funds
84
+ end
85
+
86
+ # List supported funds by name
87
+ def fund_names
88
+ self.funds.map{ |x| x[:name] }
89
+ end
90
+
91
+ # Check if the fund name is supported
92
+ def valid_fund?(fund)
93
+ self.fund_names.include?(fund)
94
+ end
95
+ end
96
+ end
@@ -2,10 +2,31 @@
2
2
 
3
3
  module Navfund
4
4
  class Sunlife < Provider
5
- # List of funds
6
5
  MAIN_URL = "http://www.sunlife.com.ph/philippines/Products+and+Services/Sun+Life+Prosperity+Funds?vgnLocale=en_CA"
7
6
  VUL_URL = "http://www.sunlife.com.ph/philippines/Products+and+Services/VUL?vgnLocale=en_CA"
8
- Funds = ["Bond Fund", "Balanced Fund", "Equity Fund", "Money Market Fund", "GS Fund", "Dollar Advantage Fund", "Dollar Abundance Fund"]
7
+ Funds = [
8
+ {:name => "Bond Fund", :currency => "PHP"},
9
+ {:name => "Balanced Fund", :currency => "PHP"},
10
+ {:name => "Equity Fund", :currency => "PHP"},
11
+ {:name => "Money Market Fund", :currency => "PHP"},
12
+ {:name => "GS Fund", :currency => "PHP"},
13
+ {:name => "Dollar Advantage Fund", :currency => "USD"},
14
+ {:name => "Dollar Abundance Fund", :currency => "USD"},
15
+ {:name => "Money Market Fund", :currency => "PHP"},
16
+ {:name => "MyFuture 2020 Fund", :currency => "PHP"},
17
+ {:name => "MyFuture 2025 Fund", :currency => "PHP"},
18
+ {:name => "MyFuture 2030 Fund", :currency => "PHP"},
19
+ {:name => "MyFuture 2035 Fund", :currency => "PHP"},
20
+ {:name => "MyFuture 2040 Fund", :currency => "PHP"},
21
+ {:name => "Income Fund", :currency => "PHP"},
22
+ {:name => "Opportunity Fund", :currency => "PHP"},
23
+ {:name => "Growth Fund", :currency => "PHP"},
24
+ {:name => "Dollar Bond Fund", :currency => "USD"},
25
+ {:name => "Sun Prestige Capital++ Fund", :currency => "USD"},
26
+ {:name => "Sun Dollar Maximizer Fund", :currency => "USD"},
27
+ {:name => "Sun Dollar Maximizer - UCG Fund", :currency => "USD"},
28
+ {:name => "Sun Dollar Maximizer - UCG 2 Fund", :currency => "USD"}
29
+ ]
9
30
 
10
31
  def initialize
11
32
  @url = MAIN_URL
@@ -38,12 +59,19 @@ module Navfund
38
59
  val
39
60
  end
40
61
 
41
- def valid_fund?(fund)
42
- Funds.include?(fund)
43
- end
44
-
62
+ # List supported funds
45
63
  def funds
46
64
  Funds
47
65
  end
66
+
67
+ # List supported funds by name
68
+ def fund_names
69
+ self.funds.map{ |x| x[:name] }
70
+ end
71
+
72
+ # Check if the fund name is supported
73
+ def valid_fund?(fund)
74
+ self.fund_names.include?(fund)
75
+ end
48
76
  end
49
77
  end
@@ -1,3 +1,3 @@
1
1
  module Navfund
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -3,18 +3,24 @@ require_relative '../../test_helper'
3
3
  describe Navfund do
4
4
  before do
5
5
  @sunlife = Navfund::Sunlife.new
6
+ @philamlife = Navfund::Philamlife.new
6
7
  end
7
8
  describe "when a provider is given" do
8
9
  it "should get the provider object" do
9
10
  @sunlife.wont_be_nil
11
+ @philamlife.wont_be_nil
10
12
  end
11
13
  it "should get the current value back in the response" do
12
- Navfund::Sunlife::Funds.each do |fund|
14
+ @sunlife.fund_names.each do |fund|
13
15
  @sunlife.value(fund).wont_be_nil
14
16
  end
17
+ @philamlife.fund_names.each do |fund|
18
+ @philamlife.value(fund).wont_be_nil
19
+ end
15
20
  end
16
21
  it "should get the current value back in the response when :vul is set" do
17
22
  @sunlife.value("Bond Fund", :vul).wont_be_nil
23
+ @philamlife.value("PELAC DOLLAR BOND FUND", :vul).wont_be_nil
18
24
  end
19
25
  end
20
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navfund
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-14 00:00:00.000000000 Z
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -60,6 +60,7 @@ files:
60
60
  - lib/navfund/navfund.rb
61
61
  - lib/navfund/provider.rb
62
62
  - lib/navfund/providers/metrobank.rb
63
+ - lib/navfund/providers/philamlife.rb
63
64
  - lib/navfund/providers/sunlife.rb
64
65
  - lib/navfund/utils/require_relative.rb
65
66
  - lib/navfund/version.rb