navfund 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Navfund is a ruby gem that fetches the values of the current NAVPU/NAVPS of several Banks/Providers of UITFs/Mutual Funds. Currently it only supports Philippine providers.
4
4
 
5
+ [![Build Status](https://travis-ci.org/marvs/navfund.png)](https://travis-ci.org/marvs/navfund)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -4,12 +4,55 @@ module Navfund
4
4
  class Metrobank < Provider
5
5
  # List of funds
6
6
  MAIN_URL = "http://www.metrobank.com.ph/trust_product.asp"
7
- Funds = [""]
7
+ Funds = [
8
+ {:name => "Money Market Fund", :currency => "PHP", :type => "main"},
9
+ {:name => "Max-3 Bond Fund", :currency => "PHP", :type => "main"},
10
+ {:name => "Wealth Builder Fund", :currency => "PHP", :type => "main"},
11
+ {:name => "Max-5 Bond Fund", :currency => "PHP", :type => "main"},
12
+ {:name => "Balanced Fund", :currency => "PHP", :type => "main"},
13
+ {:name => "Equity Fund", :currency => "PHP", :type => "main"},
14
+ {:name => "$ Money Market Fund", :currency => "USD", :type => "main"},
15
+ {:name => "$ Max-3 Bond Fund", :currency => "USD", :type => "main"},
16
+ {:name => "$ Max-5 Bond Fund", :currency => "USD", :type => "main"}
17
+ ]
8
18
 
9
19
  def initialize
10
20
  @url = MAIN_URL
11
21
  self.scrape
12
22
  end
13
23
 
24
+ # Fetch the current value
25
+ def value(fund, fund_type=nil)
26
+ val = nil
27
+ fund_type = fund_type.to_sym if fund_type.is_a?(String)
28
+ # Set fund_type to nil if VUL page is not present
29
+ fund_type = nil if fund_type == :vul && @wrapped_vul_document.nil?
30
+ if valid_fund?(fund)
31
+ source_document = (fund_type == :vul) ? @wrapped_vul_document : @wrapped_document
32
+ fname = source_document.search("[text()*='#{fund}']").first
33
+ if fname
34
+ fval = fname.parent.next_element rescue nil
35
+ end
36
+ val = Provider.strip_value(fval.text) if fval
37
+ else
38
+ raise InvalidFund
39
+ end
40
+ val
41
+ end
42
+
43
+ # List supported funds
44
+ def funds
45
+ Funds
46
+ end
47
+
48
+ # List supported funds by name
49
+ def fund_names
50
+ self.funds.map{ |x| x[:name] }
51
+ end
52
+
53
+ # Check if the fund name is supported
54
+ def valid_fund?(fund)
55
+ self.fund_names.include?(fund)
56
+ end
14
57
  end
15
58
  end
@@ -1,36 +1,37 @@
1
1
  # Philam Life
2
+ # old main - http://www.philamlife.com/en/individuals/resources-and-guides/fund-prices/philam-life-variable-funds/philam_life_variable_funds.html
2
3
 
3
4
  module Navfund
4
5
  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
+ MAIN_URL = "https://portal.philamlife.com/NAVPU/philamlife"
6
7
  VUL_URL = "http://www.philamlife.com/en/individuals/resources-and-guides/fund-prices/pelac-variable-funds/pelac_variable_funds.html"
7
8
  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"}
9
+ {:name => "PAMI PHILAM BOND FUND", :currency => "PHP", :type => "main"},
10
+ {:name => "PAMI PHILAM FUND", :currency => "PHP", :type => "main"},
11
+ {:name => "PAMI PHILAM STRATEGIC GROWTH FUND", :currency => "PHP", :type => "main"},
12
+ {:name => "PESO FIXED INCOME FUND", :currency => "PHP", :type => "main"},
13
+ {:name => "PESO EQUITY FUND", :currency => "PHP", :type => "main"},
14
+ {:name => "PESO BALANCED FUND", :currency => "PHP", :type => "main"},
15
+ {:name => "DOLLAR BOND FUND", :currency => "USD", :type => "main"},
16
+ {:name => "DOLLAR GLOBAL BOND FUND", :currency => "USD", :type => "main"},
17
+ {:name => "DOLLAR HIGH-WATER MARK FUND 2019", :currency => "USD", :type => "main"},
18
+ {:name => "PRINCIPAL PROTECT FUND 1", :currency => "PHP", :type => "main"},
19
+ {:name => "PRINCIPAL PROTECT FUND 2", :currency => "PHP", :type => "main"},
20
+ {:name => "PRINCIPAL PROTECT EMERGING MARKETS FUND", :currency => "PHP", :type => "main"},
21
+ {:name => "ASIA'S BEST FUND 1", :currency => "PHP", :type => "main"},
22
+ {:name => "ASIA'S BEST FUND 2", :currency => "PHP", :type => "main"},
23
+ {:name => "GROWTH INVEST FUND 1", :currency => "PHP", :type => "main"},
24
+ {:name => "GROWTH INVEST FUND 2", :currency => "PHP", :type => "main"},
25
+ {:name => "GROWTH INVEST FUND 3", :currency => "PHP", :type => "main"},
26
+ {:name => "PELAC PESO EQUITY FUND", :currency => "PHP", :type => "vul"},
27
+ {:name => "PELAC PESO BALANCED FUND", :currency => "PHP", :type => "vul"},
28
+ {:name => "PELAC PESO FIXED INCOME FUND", :currency => "PHP", :type => "vul"},
29
+ {:name => "PELAC DOLLAR BOND FUND", :currency => "USD", :type => "vul"},
30
+ {:name => "PELAC GLOBAL BOND FUND", :currency => "PHP", :type => "vul"},
31
+ {:name => "PELAC DOLLAR HIGH-WATER MARK FUND 2019", :currency => "USD", :type => "vul"},
32
+ {:name => "PELAC PRINCIPAL PROTECT FUND 1", :currency => "PHP", :type => "vul"},
33
+ {:name => "PELAC PRINCIPAL PROTECT FUND 2", :currency => "PHP", :type => "vul"},
34
+ {:name => "PELAC PRINCIPAL PROTECT EMERGING MARKETS FUND", :currency => "PHP", :type => "vul"}
34
35
  ]
35
36
 
36
37
  def initialize
@@ -45,18 +46,25 @@ module Navfund
45
46
  # It is possible that the same fund name is used for VUL and non-VUL funds so this is necessary
46
47
  def value(fund, fund_type=nil)
47
48
  val = nil
49
+ fund_type = fund_type.to_sym if fund_type.is_a?(String)
48
50
  # Set fund_type to nil if VUL page is not present
49
51
  fund_type = nil if fund_type == :vul && @wrapped_vul_document.nil?
50
52
  if valid_fund?(fund)
51
53
  source_document = (fund_type == :vul) ? @wrapped_vul_document : @wrapped_document
52
54
  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)
55
+ if fund_type == :vul
58
56
  fval = fname.next_element.next_element rescue nil
57
+ else
58
+ fval = fname.parent.next_element rescue nil
59
59
  end
60
+ #fname = find_fund_node(source_document, fund)
61
+ #if fname
62
+ # fval = fname.next_element.next_element rescue nil
63
+ #elsif @wrapped_vul_document && fund_type != :vul
64
+ # # Search VUL page (if its not done before)
65
+ # fname = find_fund_node(@wrapped_vul_document, fund)
66
+ # fval = fname.next_element.next_element rescue nil
67
+ #end
60
68
  val = Provider.strip_value(fval.text) if fval
61
69
  else
62
70
  raise InvalidFund
@@ -5,27 +5,33 @@ module Navfund
5
5
  MAIN_URL = "http://www.sunlife.com.ph/philippines/Products+and+Services/Sun+Life+Prosperity+Funds?vgnLocale=en_CA"
6
6
  VUL_URL = "http://www.sunlife.com.ph/philippines/Products+and+Services/VUL?vgnLocale=en_CA"
7
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"}
8
+ {:name => "Bond Fund", :currency => "PHP", :type => "main"},
9
+ {:name => "Balanced Fund", :currency => "PHP", :type => "main"},
10
+ {:name => "Equity Fund", :currency => "PHP", :type => "main"},
11
+ {:name => "Money Market Fund", :currency => "PHP", :type => "main"},
12
+ {:name => "GS Fund", :currency => "PHP", :type => "main"},
13
+ {:name => "Dollar Advantage Fund", :currency => "USD", :type => "main"},
14
+ {:name => "Dollar Abundance Fund", :currency => "USD", :type => "main"},
15
+ {:name => "Money Market Fund", :currency => "PHP", :type => "vul"},
16
+ {:name => "Bond Fund", :currency => "PHP", :type => "vul"},
17
+ {:name => "Balanced Fund", :currency => "PHP", :type => "vul"},
18
+ {:name => "Equity Fund", :currency => "PHP", :type => "vul"},
19
+ {:name => "MyFuture 2020 Fund", :currency => "PHP", :type => "vul"},
20
+ {:name => "MyFuture 2025 Fund", :currency => "PHP", :type => "vul"},
21
+ {:name => "MyFuture 2030 Fund", :currency => "PHP", :type => "vul"},
22
+ {:name => "MyFuture 2035 Fund", :currency => "PHP", :type => "vul"},
23
+ {:name => "MyFuture 2040 Fund", :currency => "PHP", :type => "vul"},
24
+ {:name => "Income Fund", :currency => "PHP", :type => "vul"},
25
+ {:name => "Opportunity Fund", :currency => "PHP", :type => "vul"},
26
+ {:name => "Growth Fund", :currency => "PHP", :type => "vul"},
27
+ {:name => "Dollar Bond Fund", :currency => "USD", :type => "vul"},
28
+ {:name => "Global Income Fund", :currency => "USD", :type => "vul"},
29
+ {:name => "Sun Prestige Capital++ Fund", :currency => "USD", :type => "vul"},
30
+ {:name => "Sun Dollar Maximizer Fund", :currency => "USD", :type => "vul"},
31
+ {:name => "Sun Dollar Maximizer - UCG Fund", :currency => "USD", :type => "vul"},
32
+ {:name => "Sun Dollar Maximizer - UCG 2 Fund", :currency => "USD", :type => "vul"},
33
+ {:name => "Sun Dollar Maximizer - EA Fund", :currency => "USD", :type => "vul"},
34
+ {:name => "Sun Dollar Maximizer - EA 2 Fund", :currency => "USD", :type => "vul"}
29
35
  ]
30
36
 
31
37
  def initialize
@@ -40,6 +46,7 @@ module Navfund
40
46
  # It is possible that the same fund name is used for VUL and non-VUL funds so this is necessary
41
47
  def value(fund, fund_type=nil)
42
48
  val = nil
49
+ fund_type = fund_type.to_sym if fund_type.is_a?(String)
43
50
  # Set fund_type to nil if VUL page is not present
44
51
  fund_type = nil if fund_type == :vul && @wrapped_vul_document.nil?
45
52
  if valid_fund?(fund)
@@ -1,3 +1,3 @@
1
1
  module Navfund
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,4 +1,4 @@
1
- require_relative '../../test_helper'
1
+ require File.expand_path('../../../test_helper.rb', __FILE__)
2
2
 
3
3
  describe Navfund do
4
4
 
@@ -1,26 +1,22 @@
1
- require_relative '../../test_helper'
1
+ require File.expand_path('../../../test_helper.rb', __FILE__)
2
2
 
3
3
  describe Navfund do
4
4
  before do
5
5
  @sunlife = Navfund::Sunlife.new
6
- @philamlife = Navfund::Philamlife.new
6
+ @metrobank = Navfund::Metrobank.new
7
7
  end
8
8
  describe "when a provider is given" do
9
9
  it "should get the provider object" do
10
10
  @sunlife.wont_be_nil
11
- @philamlife.wont_be_nil
11
+ @metrobank.wont_be_nil
12
12
  end
13
13
  it "should get the current value back in the response" do
14
- @sunlife.fund_names.each do |fund|
15
- @sunlife.value(fund).wont_be_nil
14
+ @sunlife.funds.each do |fund|
15
+ @sunlife.value(fund[:name], fund[:type]).wont_be_nil
16
16
  end
17
- @philamlife.fund_names.each do |fund|
18
- @philamlife.value(fund).wont_be_nil
17
+ @metrobank.funds.each do |fund|
18
+ @metrobank.value(fund[:name], fund[:type]).wont_be_nil
19
19
  end
20
20
  end
21
- it "should get the current value back in the response when :vul is set" do
22
- @sunlife.value("Bond Fund", :vul).wont_be_nil
23
- @philamlife.value("PELAC DOLLAR BOND FUND", :vul).wont_be_nil
24
- end
25
21
  end
26
22
  end
@@ -1,4 +1,4 @@
1
- require_relative '../../test_helper'
1
+ require File.expand_path('../../../test_helper.rb', __FILE__)
2
2
 
3
3
  describe Navfund do
4
4
  it "must be defined" do
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.4
4
+ version: 0.0.5
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-21 00:00:00.000000000 Z
12
+ date: 2013-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -51,6 +51,7 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
53
  - .gitignore
54
+ - .travis.yml
54
55
  - Gemfile
55
56
  - LICENSE
56
57
  - README.md
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
90
  version: '0'
90
91
  requirements: []
91
92
  rubyforge_project:
92
- rubygems_version: 1.8.21
93
+ rubygems_version: 1.8.25
93
94
  signing_key:
94
95
  specification_version: 3
95
96
  summary: Navfund is a ruby gem that fetches the values of the current NAVPU/NAVPS