navfund 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f151b4c54ed06165673a1e4ae046f97e4b4d31f4
4
+ data.tar.gz: b8ec4a7016ca040ff104a7d4d6eb2526d9ab3068
5
+ SHA512:
6
+ metadata.gz: ba372171a218b9fad5a3a6f8ba31637afe566eaf0a2a0eadce6200327b445827a495afa6891b0c6579381a1fce7d4c2aef6d5ac26c3d98c3954c77c52732388d
7
+ data.tar.gz: 93035f56bf3ca1aa74cdc07b1dab82f8c3f75d9d14ee64c380c36f72f3b3edcf4ffc48ac414988ae0b6acb025f764e973477b7c42e00aad928c6e3142fef15a3
data/.travis.yml CHANGED
@@ -2,3 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Marvin Baltazar
1
+ Copyright (c) 2015 Marvin Baltazar
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # Navfund
2
2
 
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.
3
+ Navfund is a ruby gem that fetches the values of the current NAVPU/NAVPS of several UITFs/Mutual Funds. Currently it only supports Philippine providers.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/navfund.svg)](http://badge.fury.io/rb/navfund)
5
6
  [![Build Status](https://travis-ci.org/marvs/navfund.png)](https://travis-ci.org/marvs/navfund)
6
7
 
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
@@ -26,22 +28,29 @@ Get a list of supported Providers:
26
28
 
27
29
  Initialize a Provider's data:
28
30
 
29
- @sunlife = Navfund::Sunlife.new
31
+ @metrobank = Navfund::Metrobank.new
30
32
 
31
33
  To get a list of supported funds for a specific Provider:
32
34
 
33
- Navfund::Sunlife::Funds
34
- @sunlife.funds # if a provider is initialized
35
+ Navfund::Metrobank::Funds
36
+ @metrobank.funds # if a provider is initialized
35
37
 
36
38
  Get the current NAVPU/NAVPS of a fund, by name:
37
39
 
38
- @sunlife.value("Bond Fund")
40
+ @metrobank.value("Equity Fund")
39
41
 
40
- Some Providers have a separate page when listing VUL (Variable Unit Life Insurance) fund values. To get the VUL value by name, add a :vul option when calling the value method. It is possible that the same name is used for both VUL and non-VUL funds:
42
+ A Navfund::Provider::InvalidFund will be raised if the specified fund is not supported or is invalid.
43
+
44
+ Get the date in which the value is valid. This returns a Date object:
45
+
46
+ @metrobank.value_at
41
47
 
42
- @sunlife.value("Bond Fund", :vul)
48
+ To list all fund names with their current values:
49
+
50
+ @metrobank.fund_values
43
51
 
44
- A Navfund::Provider::InvalidFund will be raised if the specified fund is not supported or is invalid.
52
+ This returns an array of hashes with all the fund names and their current values.
53
+
45
54
 
46
55
  ## Testing
47
56
 
data/lib/navfund.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'nokogiri'
2
2
  require 'open-uri'
3
+ require 'openssl'
4
+ require 'date'
3
5
 
4
6
  # Add current directory to load paths
5
7
  main_dir = File.dirname(__FILE__)
@@ -18,7 +20,13 @@ require "navfund/provider"
18
20
  require "navfund/providers/metrobank"
19
21
  require "navfund/providers/sunlife"
20
22
  require "navfund/providers/philamlife"
23
+ require "navfund/providers/bdo_unibank"
24
+ require "navfund/providers/bpi"
25
+ require "navfund/providers/philippine_national_bank"
26
+ require "navfund/providers/security_bank"
27
+ require "navfund/providers/union_bank"
28
+ require "navfund/providers/ucpb"
21
29
 
22
30
  module Navfund
23
- Providers = [Metrobank, Sunlife, Philamlife]
31
+ Providers = [Metrobank, Sunlife, Philamlife, BDO, BPI, PNB, SecurityBank, UnionBank, UCPB]
24
32
  end
@@ -2,22 +2,67 @@
2
2
 
3
3
  module Navfund
4
4
  class Provider
5
+ attr_reader :funds
5
6
 
6
- def scrape
7
- @document = open(@url).read
8
- @wrapped_document = Nokogiri::HTML(@document)
9
- if @vul_url
10
- @vul_document = open(@vul_url).read
11
- @wrapped_vul_document = Nokogiri::HTML(@vul_document)
7
+ def scrape(opts={})
8
+ if opts[:check_ssl] == false
9
+ @document = open(@url, :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read
10
+ else
11
+ @document = open(@url).read
12
12
  end
13
+ @wrapped_document = Nokogiri::HTML(@document)
13
14
  end
14
15
 
15
16
  def self.strip_value(val)
16
- val.strip.gsub('PHP', '').gsub('USD', '').strip
17
+ val.strip.gsub('PHP', '').gsub('USD', '').gsub(',', '').strip
18
+ end
19
+
20
+ # List supported funds by name
21
+ def fund_names
22
+ funds.map{ |x| x[:name] }
17
23
  end
18
24
 
25
+ # Check if the fund name is supported
19
26
  def valid_fund?(fund)
20
- false
27
+ fund_names.include?(fund)
28
+ end
29
+
30
+ # Returns the fund value
31
+ def value
32
+ nil
33
+ end
34
+
35
+ # Returns the date of the fund values
36
+ def value_at
37
+ nil
38
+ end
39
+
40
+ # Display all fund values
41
+ def fund_values
42
+ fvals = []
43
+ fund_names.each{ |f| fvals << { :name => f, :value => self.value(f) } }
44
+ fvals
45
+ end
46
+
47
+ # Generic parser for uitf.com.ph website
48
+ def uitf_com_ph_parser(fund)
49
+ val = nil
50
+ if valid_fund?(fund)
51
+ fname = @wrapped_document.search("[text()*='#{fund}']").first
52
+ if fname
53
+ fval = fname.ancestors('tr').first.search("td[data-title='NAVpu'] div").first rescue nil
54
+ end
55
+ val = Provider.strip_value(fval.text) if fval
56
+ else
57
+ raise InvalidFund
58
+ end
59
+ val
60
+ end
61
+
62
+ def uitf_com_ph_date_parser
63
+ dtext = @wrapped_document.search("h5").first.text
64
+ dstr = dtext.split("as of").last.strip
65
+ Date.parse(dstr)
21
66
  end
22
67
 
23
68
  end
@@ -0,0 +1,41 @@
1
+ # BDO Unibank
2
+
3
+ module Navfund
4
+ class BDO < Provider
5
+ # List of funds
6
+ MAIN_URL = "http://www.uitf.com.ph/daily_navpu.php?bank_id=6"
7
+ Funds = [
8
+ {:name => "INSTITUTIONAL CASH RESERVE FUND", :currency => "PHP", :ticker => "BDOICRF:PM"},
9
+ {:name => "PESO MONEY MARKET FUND", :currency => "PHP", :ticker => "BDOPMMF:PM"},
10
+ {:name => "MERIT FUND SHORT TERM PORTFOLIO", :currency => "PHP", :ticker => "EPCIBME:PM"},
11
+ {:name => "GS FUND", :currency => "PHP", :ticker => "EPCIBGS:PM"},
12
+ {:name => "MERIT FUND MEDIUM TERM PORTFOLIO", :currency => "PHP", :ticker => "BDOMERB:PM"},
13
+ {:name => "PESO BOND FUND", :currency => "PHP", :ticker => "BDOPBF:PM"},
14
+ {:name => "PESO FIXED INCOME FUND", :currency => "PHP", :ticker => "BDOPFIF:PM"},
15
+ {:name => "PESO BALANCED FUND", :currency => "PHP", :ticker => "BDOPBAL:PM"},
16
+ {:name => "EQUITY FUND", :currency => "PHP", :ticker => "EPCIBEQ:PM"},
17
+ {:name => "FOCUSED EQUITY FUND", :currency => "PHP", :ticker => "BDOTFEF:PM"},
18
+ {:name => "INSTITUTIONAL EQUITY FUND", :currency => "PHP", :ticker => "BDOEQTY:PM"},
19
+ {:name => "SUSTAINABLE DIVIDEND FUND", :currency => "PHP", :ticker => "BDOTSDF:PM"},
20
+ {:name => "DOLLAR MONEY MARKET FUND", :currency => "USD", :ticker => "BDODMMF:PM"},
21
+ {:name => "DOLLAR BOND FUND", :currency => "USD", :ticker => "BDODBF:PM"},
22
+ {:name => "MEDIUM TERM DOLLAR BOND FUND", :currency => "USD", :ticker => "EPCIBUS:PM"}
23
+ ]
24
+
25
+ def initialize(main_url=nil)
26
+ @url = main_url ||= MAIN_URL
27
+ @funds = Funds
28
+ scrape
29
+ end
30
+
31
+ # Fetch the current value
32
+ def value(fund, fund_type=nil)
33
+ uitf_com_ph_parser(fund)
34
+ end
35
+
36
+ def value_at
37
+ uitf_com_ph_date_parser
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,52 @@
1
+ # Bank of the Philippine Islands
2
+
3
+ module Navfund
4
+ class BPI < Provider
5
+ # List of funds
6
+ MAIN_URL = "http://www.uitf.com.ph/daily_navpu.php?bank_id=3"
7
+ Funds = [
8
+ {:name => "BPI Money Market Fund", :currency => "PHP", :ticker => "BPINSTI:PM"},
9
+ {:name => "BPI Short Term Fund", :currency => "PHP", :ticker => "BPSTUIT:PM"},
10
+ {:name => "Odyssey Peso Cash Management Fund", :currency => "PHP", :ticker => "INGPCSH:PM"},
11
+ {:name => "BPI Premium Bond Fund", :currency => "PHP", :ticker => "BPIPRUI:PM"},
12
+ {:name => "Odyssey Peso Income Fund", :currency => "PHP", :ticker => "INGPINC:PM"},
13
+ {:name => "ABF Philippines Bond Index Fund", :currency => "PHP", :ticker => "ABFPH:PM"},
14
+ {:name => "Odyssey Peso Bond Fund", :currency => "PHP", :ticker => "INGPFIN:PM"},
15
+ {:name => "Odyssey Tax-Exempt Peso Fixed Income Fund", :currency => "PHP", :ticker => "INGTEFI:PM"},
16
+ {:name => "BPI Balanced Fund", :currency => "PHP", :ticker => "BPIEQBL:PM"},
17
+ {:name => "Odyssey Diversified Balanced Fund", :currency => "PHP", :ticker => "INGDVBA:PM"},
18
+ {:name => "Odyssey Diversified Capital Fund", :currency => "PHP", :ticker => "INGDVCP:PM"},
19
+ {:name => "BPI Equity Value Fund", :currency => "PHP", :ticker => "BPIEQUI:PM"},
20
+ {:name => "BPI Philippine Equity Index Fund", :currency => "PHP", :ticker => "BPIPEIF:PM"},
21
+ {:name => "BPI Philippine High Dividend Equity Fund", :currency => "PHP", :ticker => "BPPHDEF:PM"},
22
+ {:name => "Odyssey High Conviction Equity Fund", :currency => "PHP", :ticker => "INGPHCE:PM"},
23
+ {:name => "Odyssey Philippine Equity Fund", :currency => "PHP", :ticker => "INGPHEQ:PM"},
24
+ {:name => "Odyssey Tax-Exempt Philippine Equity Fund", :currency => "PHP", :ticker => "INGTEPE:PM"},
25
+ {:name => "BPI Global Bond Fund-of-Funds", :currency => "USD", :ticker => "BPIINFP:PM"},
26
+ {:name => "BPI Global Philippine Fund", :currency => "USD", :ticker => "BPIGLPH:PM"},
27
+ {:name => "Odyssey Emerging Market Bond Fund", :currency => "USD", :ticker => "INGUSIN:PM"},
28
+ {:name => "Odyssey Philippine Dollar Bond Fund", :currency => "USD", :ticker => "INGPDFI:PM"},
29
+ {:name => "Philippine Dollar Bond Index Fund", :currency => "USD", :ticker => "BPIDBIX:PM"},
30
+ {:name => "BPI European Equity Index Feeder Fund", :currency => "USD", :ticker => "BPIEUFF:PM"},
31
+ {:name => "BPI Global Equity Fund-of-Funds", :currency => "USD", :ticker => "BPIGLBL:PM"},
32
+ {:name => "BPI US Equity Index Feeder Fund", :currency => "USD", :ticker => "BPIUSFF:PM"},
33
+ {:name => "Odyssey Asia Pacific High Dividend Equity Fund", :currency => "USD", :ticker => "INGAPHD:PM"}
34
+ ]
35
+
36
+ def initialize(main_url=nil)
37
+ @url = main_url ||= MAIN_URL
38
+ @funds = Funds
39
+ scrape
40
+ end
41
+
42
+ # Fetch the current value
43
+ def value(fund, fund_type=nil)
44
+ uitf_com_ph_parser(fund)
45
+ end
46
+
47
+ def value_at
48
+ uitf_com_ph_date_parser
49
+ end
50
+
51
+ end
52
+ end
@@ -3,56 +3,35 @@
3
3
  module Navfund
4
4
  class Metrobank < Provider
5
5
  # List of funds
6
- MAIN_URL = "http://www.metrobank.com.ph/trust_product.asp"
6
+ MAIN_URL = "http://www.uitf.com.ph/daily_navpu.php?bank_id=1"
7
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"}
8
+ {:name => "Money Market Fund", :currency => "PHP", :ticker => "MBSTART:PM"},
9
+ {:name => "Max-3 Bond Fund", :currency => "PHP", :ticker => "MBELITE:PM"},
10
+ {:name => "Wealth Builder Fund", :currency => "PHP", :ticker => "MBIPLUS:PM"},
11
+ {:name => "Max-5 Bond Fund", :currency => "PHP", :ticker => "MBPKEAR:PM"},
12
+ {:name => "Balanced Fund", :currency => "PHP", :ticker => "MBCAPGR:PM"},
13
+ {:name => "Equity Fund", :currency => "PHP", :ticker => "MBEQITY:PM"},
14
+ {:name => "High Dividend Yield Fund", :currency => "PHP", :ticker => ""},
15
+ {:name => "PSEi Tracker Fund", :currency => "PHP", :ticker => ""},
16
+ {:name => "$ Money Market Fund", :currency => "USD", :ticker => "MBDMMKF:PM"},
17
+ {:name => "$ Max-3 Bond Fund", :currency => "USD", :ticker => "MBPHLIQ:PM"},
18
+ {:name => "$ Max-5 Bond Fund", :currency => "USD", :ticker => "MBPHLBD:PM"}
17
19
  ]
18
-
19
- def initialize
20
- @url = MAIN_URL
21
- self.scrape
22
- end
23
20
 
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
21
+ def initialize(main_url=nil)
22
+ @url = main_url ||= MAIN_URL
23
+ @funds = Funds
24
+ scrape
41
25
  end
42
26
 
43
- # List supported funds
44
- def funds
45
- Funds
27
+ # Fetch the current value
28
+ def value(fund, fund_type=nil)
29
+ uitf_com_ph_parser(fund)
46
30
  end
47
31
 
48
- # List supported funds by name
49
- def fund_names
50
- self.funds.map{ |x| x[:name] }
32
+ def value_at
33
+ uitf_com_ph_date_parser
51
34
  end
52
35
 
53
- # Check if the fund name is supported
54
- def valid_fund?(fund)
55
- self.fund_names.include?(fund)
56
- end
57
36
  end
58
37
  end
@@ -1,70 +1,40 @@
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
3
2
 
4
3
  module Navfund
5
4
  class Philamlife < Provider
6
5
  MAIN_URL = "https://portal.philamlife.com/NAVPU/philamlife"
7
- VUL_URL = "http://www.philamlife.com/en/individuals/resources-and-guides/fund-prices/pelac-variable-funds/pelac_variable_funds.html"
8
6
  Funds = [
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"}
7
+ {:name => "PAMI PHILAM BOND FUND", :currency => "PHP", :ticker => "PHILABF:PM"},
8
+ {:name => "PAMI PHILAM FUND", :currency => "PHP", :ticker => "PHILAMF:PM"},
9
+ {:name => "PAMI PHILAM STRATEGIC GROWTH FUND", :currency => "PHP", :ticker => "PHILSTG:PM"},
10
+ {:name => "PESO FIXED INCOME FUND", :currency => "PHP", :ticker => ""},
11
+ {:name => "PESO EQUITY FUND", :currency => "PHP", :ticker => ""},
12
+ {:name => "PESO BALANCED FUND", :currency => "PHP", :ticker => ""},
13
+ {:name => "DOLLAR BOND FUND", :currency => "USD", :ticker => ""},
14
+ {:name => "DOLLAR GLOBAL BOND FUND", :currency => "USD", :ticker => ""},
15
+ {:name => "DOLLAR HIGH-WATER MARK FUND 2019", :currency => "USD", :ticker => ""},
16
+ {:name => "PRINCIPAL PROTECT FUND 1", :currency => "PHP", :ticker => ""},
17
+ {:name => "PRINCIPAL PROTECT FUND 2", :currency => "PHP", :ticker => ""},
18
+ {:name => "PRINCIPAL PROTECT EMERGING MARKETS FUND", :currency => "PHP", :ticker => ""},
19
+ {:name => "ASIA'S BEST FUND 1", :currency => "PHP", :ticker => ""},
20
+ {:name => "ASIA'S BEST FUND 2", :currency => "PHP", :ticker => ""},
21
+ {:name => "GROWTH INVEST FUND 1", :currency => "PHP", :ticker => ""},
22
+ {:name => "GROWTH INVEST FUND 2", :currency => "PHP", :ticker => ""},
23
+ {:name => "GROWTH INVEST FUND 3", :currency => "PHP", :ticker => ""}
35
24
  ]
36
25
 
37
- def initialize
38
- @url = MAIN_URL
39
- @vul_url = VUL_URL
40
- self.scrape
26
+ def initialize(main_url=nil)
27
+ @url = main_url ||= MAIN_URL
28
+ @funds = Funds
29
+ self.scrape(:check_ssl => false)
41
30
  end
42
31
 
43
32
  # Fetch the current value
44
- # Some providers have a separate page for VUL funds, to force checking the VUL page,
45
- # set the type to :vul, for example @sunlife.value("Bond Fund", :vul)
46
- # It is possible that the same fund name is used for VUL and non-VUL funds so this is necessary
47
33
  def value(fund, fund_type=nil)
48
34
  val = nil
49
- fund_type = fund_type.to_sym if fund_type.is_a?(String)
50
- # Set fund_type to nil if VUL page is not present
51
- fund_type = nil if fund_type == :vul && @wrapped_vul_document.nil?
52
35
  if valid_fund?(fund)
53
- source_document = (fund_type == :vul) ? @wrapped_vul_document : @wrapped_document
54
- fname = find_fund_node(source_document, fund)
55
- if fund_type == :vul
56
- fval = fname.next_element.next_element rescue nil
57
- else
58
- fval = fname.parent.next_element rescue nil
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
36
+ fname = find_fund_node(@wrapped_document, fund)
37
+ fval = fname.parent.next_element rescue nil
68
38
  val = Provider.strip_value(fval.text) if fval
69
39
  else
70
40
  raise InvalidFund
@@ -72,6 +42,12 @@ module Navfund
72
42
  val
73
43
  end
74
44
 
45
+ def value_at
46
+ dcontainer = @wrapped_document.search('div#detailcol3').first
47
+ dtext = dcontainer.text.strip
48
+ Date.strptime(dtext, "%m/%d/%Y")
49
+ end
50
+
75
51
  def find_fund_node(doc, fund)
76
52
  fname = nil
77
53
  if fund.match(/'/)
@@ -86,19 +62,5 @@ module Navfund
86
62
  fname
87
63
  end
88
64
 
89
- # List supported funds
90
- def funds
91
- Funds
92
- end
93
-
94
- # List supported funds by name
95
- def fund_names
96
- self.funds.map{ |x| x[:name] }
97
- end
98
-
99
- # Check if the fund name is supported
100
- def valid_fund?(fund)
101
- self.fund_names.include?(fund)
102
- end
103
65
  end
104
66
  end
@@ -0,0 +1,40 @@
1
+ # Philippine National Bank
2
+
3
+ module Navfund
4
+ class PNB < Provider
5
+ # List of funds
6
+ MAIN_URL = "http://www.uitf.com.ph/daily_navpu.php?bank_id=2"
7
+ Funds = [
8
+ {:name => "DREAM BUILDER MONEY MARKET FUND", :currency => "PHP", :ticker => ""},
9
+ {:name => "GLOBAL FILIPINO PESO MONEY MARKET FUND", :currency => "PHP", :ticker => "PNBPSPL:PM"},
10
+ {:name => "INSTITUTIONAL MONEY MARKET FUND", :currency => "PHP", :ticker => ""},
11
+ {:name => "PRIME PESO MONEY MARKET FUND", :currency => "PHP", :ticker => "PNBMHPR:PM"},
12
+ {:name => "AUP GS FUND", :currency => "PHP", :ticker => "ALDUPGS:PM"},
13
+ {:name => "PLUS INTERMEDIATE TERM BOND FUND", :currency => "PHP", :ticker => "PNBDRMB:PM"},
14
+ {:name => "PRESTIGE BALANCED FUND", :currency => "PHP", :ticker => "PNBMHPT:PM"},
15
+ {:name => "AUP EQUITY FUND", :currency => "PHP", :ticker => "ALDUPEQ:PM"},
16
+ {:name => "ENHANCED PHIL-INDEX REFERENCE FUND", :currency => "PHP", :ticker => "PNBPHSX:PM"},
17
+ {:name => "HIGH DIVIDEND FUND", :currency => "PHP", :ticker => "PNBHIDF:PM"},
18
+ {:name => "GLOBAL FILIPINO DOLLAR MONEY MARKET FUND", :currency => "USD", :ticker => "PNBDLPL:PM"},
19
+ {:name => "PRIME DOLLAR MONEY MARKET FUND", :currency => "USD", :ticker => "PNBDPRF:PM"},
20
+ {:name => "PROFIT DOLLAR INTERMEDIATE TERM BOND FUND", :currency => "USD", :ticker => "PNBDLPR:PM"},
21
+ {:name => "AUP DOLLAR FUND", :currency => "USD", :ticker => "ALDUPDL:PM"}
22
+ ]
23
+
24
+ def initialize(main_url=nil)
25
+ @url = main_url ||= MAIN_URL
26
+ @funds = Funds
27
+ scrape
28
+ end
29
+
30
+ # Fetch the current value
31
+ def value(fund, fund_type=nil)
32
+ uitf_com_ph_parser(fund)
33
+ end
34
+
35
+ def value_at
36
+ uitf_com_ph_date_parser
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,34 @@
1
+ # Security Bank
2
+
3
+ module Navfund
4
+ class SecurityBank < Provider
5
+ # List of funds
6
+ MAIN_URL = "http://www.uitf.com.ph/daily_navpu.php?bank_id=12"
7
+ Funds = [
8
+ {:name => "SB PESO MONEY MARKET FUND", :currency => "PHP", :ticker => "SBPSOEA:PM"},
9
+ {:name => "SB Intermediate Term Peso Bond Fund", :currency => "PHP", :ticker => "SBITPBD:PM"},
10
+ {:name => "SB PESO BOND FUND", :currency => "PHP", :ticker => "SBPSUIT:PM"},
11
+ {:name => "SB TAX-EXEMPT BOND FUND", :currency => "PHP", :ticker => "SBTEXBD:PM"},
12
+ {:name => "SB PESO ASSET VARIETY FUND", :currency => "PHP", :ticker => "SBPSASV:PM"},
13
+ {:name => "SB HIGH DIVIDEND PESO EQUITY FUND", :currency => "PHP", :ticker => "SBPSHDF:PM"},
14
+ {:name => "SB PESO EQUITY FUND", :currency => "PHP", :ticker => "SBPSEQF:PM"},
15
+ {:name => "SB DOLLAR BOND FUND", :currency => "USD", :ticker => "SBDLUIT:PM"}
16
+ ]
17
+
18
+ def initialize(main_url=nil)
19
+ @url = main_url ||= MAIN_URL
20
+ @funds = Funds
21
+ scrape
22
+ end
23
+
24
+ # Fetch the current value
25
+ def value(fund, fund_type=nil)
26
+ uitf_com_ph_parser(fund)
27
+ end
28
+
29
+ def value_at
30
+ uitf_com_ph_date_parser
31
+ end
32
+
33
+ end
34
+ end
@@ -3,62 +3,28 @@
3
3
  module Navfund
4
4
  class Sunlife < Provider
5
5
  MAIN_URL = "http://www.sunlife.com.ph/philippines/Products+and+Services/Sun+Life+Prosperity+Funds?vgnLocale=en_CA"
6
- VUL_URL = "http://www.sunlife.com.ph/philippines/Products+and+Services/VUL?vgnLocale=en_CA"
7
6
  Funds = [
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"}
7
+ {:name => "Bond Fund", :currency => "PHP", :ticker => "SNCPRBF:PM"},
8
+ {:name => "Balanced Fund", :currency => "PHP", :ticker => "SNCPRBA:PM"},
9
+ {:name => "Equity Fund", :currency => "PHP", :ticker => "SNCPPEA:PM"},
10
+ {:name => "Money Market Fund", :currency => "PHP", :ticker => "SNLFMNY:PM"},
11
+ {:name => "GS Fund", :currency => "PHP", :ticker => "SNLPRGS:PM"},
12
+ {:name => "Dollar Advantage Fund", :currency => "USD", :ticker => "SUNPDAA:PM"},
13
+ {:name => "Dollar Abundance Fund", :currency => "USD", :ticker => "SNLPRDA:PM"}
35
14
  ]
36
15
 
37
- def initialize
16
+ def initialize(main_url=nil)
17
+ @url = main_url ||= MAIN_URL
38
18
  @url = MAIN_URL
39
- @vul_url = VUL_URL
40
19
  self.scrape
41
20
  end
42
21
 
43
22
  # Fetch the current value
44
- # Some providers have a separate page for VUL funds, to force checking the VUL page,
45
- # set the type to :vul, for example @sunlife.value("Bond Fund", :vul)
46
- # It is possible that the same fund name is used for VUL and non-VUL funds so this is necessary
47
23
  def value(fund, fund_type=nil)
48
24
  val = nil
49
- fund_type = fund_type.to_sym if fund_type.is_a?(String)
50
- # Set fund_type to nil if VUL page is not present
51
- fund_type = nil if fund_type == :vul && @wrapped_vul_document.nil?
52
25
  if valid_fund?(fund)
53
- source_document = (fund_type == :vul) ? @wrapped_vul_document : @wrapped_document
54
- fname = source_document.search("[text()*='#{fund}']").first
55
- if fname
56
- fval = fname.parent.next_element rescue nil
57
- elsif @wrapped_vul_document && fund_type != :vul
58
- # Search VUL page (if its not done before)
59
- fname = @wrapped_vul_document.search("[text()*='#{fund}']").first
60
- fval = fname.parent.next_element rescue nil
61
- end
26
+ fname = @wrapped_document.search("[text()*='#{fund}']").first
27
+ fval = fname.parent.next_element rescue nil
62
28
  val = Provider.strip_value(fval.text) if fval
63
29
  else
64
30
  raise InvalidFund
@@ -66,19 +32,12 @@ module Navfund
66
32
  val
67
33
  end
68
34
 
69
- # List supported funds
70
- def funds
71
- Funds
35
+ def value_at
36
+ dcontainer = @wrapped_document.search("div.newsHeadlineTitle[align='left']").first
37
+ dtext = dcontainer.text
38
+ dstr = dtext.split("As of").last.strip
39
+ Date.strptime(dstr, "%m/%d/%Y")
72
40
  end
73
41
 
74
- # List supported funds by name
75
- def fund_names
76
- self.funds.map{ |x| x[:name] }
77
- end
78
-
79
- # Check if the fund name is supported
80
- def valid_fund?(fund)
81
- self.fund_names.include?(fund)
82
- end
83
42
  end
84
43
  end
@@ -0,0 +1,32 @@
1
+ # United Coconut Planter's Bank
2
+
3
+ module Navfund
4
+ class UCPB < Provider
5
+ # List of funds
6
+ MAIN_URL = "http://www.uitf.com.ph/daily_navpu.php?bank_id=14"
7
+ Funds = [
8
+ {:name => "UCPB Cash Management Fund", :currency => "PHP", :ticker => "UCPBCSH:PM"},
9
+ {:name => "UCPB Peso Bond Fund", :currency => "PHP", :ticker => "UCPBCSV:PM"},
10
+ {:name => "UCPB Balanced Fund", :currency => "PHP", :ticker => "UCPBBAL:PM"},
11
+ {:name => "UCPB Equity Fund", :currency => "PHP", :ticker => "UCPBEQT:PM"},
12
+ {:name => "UCPB High Dividend Fund", :currency => "PHP", :ticker => "UCPBHDF:PM"},
13
+ {:name => "UCPB US$ Money Market Fund", :currency => "USD", :ticker => "UCPBDMM:PM"}
14
+ ]
15
+
16
+ def initialize(main_url=nil)
17
+ @url = main_url ||= MAIN_URL
18
+ @funds = Funds
19
+ scrape
20
+ end
21
+
22
+ # Fetch the current value
23
+ def value(fund, fund_type=nil)
24
+ uitf_com_ph_parser(fund)
25
+ end
26
+
27
+ def value_at
28
+ uitf_com_ph_date_parser
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ # Union Bank
2
+
3
+ module Navfund
4
+ class UnionBank < Provider
5
+ # List of funds
6
+ MAIN_URL = "http://www.uitf.com.ph/daily_navpu.php?bank_id=13"
7
+ Funds = [
8
+ {:name => "UnionBank Peso Short Term Fixed Income Portfolio", :currency => "PHP", :ticker => "IFDPMMP:PM"},
9
+ {:name => "UnionBank Infinity Prime Fund", :currency => "PHP", :ticker => "IFDPRIM:PM"},
10
+ {:name => "UnionBank Medium Term Fixed Income Portfolio", :currency => "PHP", :ticker => ""},
11
+ {:name => "UnionBank Philippine Peso Fixed Income Portfolio", :currency => "PHP", :ticker => "IFDPPBP:PM"},
12
+ {:name => "UnionBank Long Term Fixed Income Portfolio", :currency => "PHP", :ticker => "IFDLTCI:PM"},
13
+ {:name => "UnionBank Tax Exempt Portfolio", :currency => "PHP", :ticker => ""},
14
+ {:name => "UnionBank Peso Balanced Portfolio", :currency => "PHP", :ticker => "UNPESBA:PM"},
15
+ {:name => "UnionBank Dividend Play Equity Fund", :currency => "PHP", :ticker => ""},
16
+ {:name => "UnionBank Dividend Play Equity Portfolio", :currency => "PHP", :ticker => "UBPDIVP:PM"},
17
+ {:name => "UnionBank Large Capitalization Philippine Equity Portfolio", :currency => "PHP", :ticker => "IFDLCPE:PM"},
18
+ {:name => "UnionBank Philippine Equity Index Tracker Fund Portfolio", :currency => "PHP", :ticker => "UBPHEIT:PM"},
19
+ {:name => "UnionBank Dollar Bond Portfolio", :currency => "USD", :ticker => "IFPHDLB:PM"}
20
+ ]
21
+
22
+ def initialize(main_url=nil)
23
+ @url = main_url ||= MAIN_URL
24
+ @funds = Funds
25
+ scrape
26
+ end
27
+
28
+ # Fetch the current value
29
+ def value(fund, fund_type=nil)
30
+ uitf_com_ph_parser(fund)
31
+ end
32
+
33
+ def value_at
34
+ uitf_com_ph_date_parser
35
+ end
36
+
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module Navfund
2
- VERSION = "0.0.5"
2
+ VERSION = "1.0.0"
3
3
  end
data/navfund.gemspec CHANGED
@@ -8,11 +8,14 @@ Gem::Specification.new do |gem|
8
8
  gem.authors = ["Marvin Baltazar"]
9
9
  gem.email = ["marvin.baltazar@gmail.com"]
10
10
  gem.description = %q{Data scraper for Investment Fund Net Asset Values (NAVs)}
11
- gem.summary = %q{Navfund is a ruby gem that fetches the values of the current NAVPU/NAVPS of several Banks/Providers of UITFs/Mutual Funds}
11
+ gem.summary = %q{Navfund is a ruby gem that fetches the current NAVPU/NAVPS of UITFs/Mutual Funds}
12
12
  gem.homepage = "https://github.com/marvs/navfund"
13
+ gem.license = "MIT"
13
14
 
14
- gem.add_runtime_dependency "nokogiri"
15
- gem.add_development_dependency "rake"
15
+ gem.required_ruby_version = ">= 1.9.2"
16
+
17
+ gem.add_runtime_dependency "nokogiri", "~> 1.4"
18
+ gem.add_development_dependency "rake", "~> 0.8"
16
19
 
17
20
  gem.files = `git ls-files`.split($\)
18
21
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -1,21 +1,23 @@
1
1
  require File.expand_path('../../../test_helper.rb', __FILE__)
2
2
 
3
3
  describe Navfund do
4
- before do
5
- @sunlife = Navfund::Sunlife.new
6
- @metrobank = Navfund::Metrobank.new
7
- end
8
- describe "when a provider is given" do
9
- it "should get the provider object" do
10
- @sunlife.wont_be_nil
11
- @metrobank.wont_be_nil
4
+ Navfund::Providers.each do |provider_klass|
5
+ before do
6
+ google_cache_url = "http://webcache.googleusercontent.com/search?q=cache:"
7
+ test_url = "#{google_cache_url}#{provider_klass::MAIN_URL}"
8
+ @provider = provider_klass.new(test_url)
12
9
  end
13
- it "should get the current value back in the response" do
14
- @sunlife.funds.each do |fund|
15
- @sunlife.value(fund[:name], fund[:type]).wont_be_nil
10
+ describe "for the #{provider_klass.to_s} provider" do
11
+ it "should get the #{provider_klass.to_s} object" do
12
+ @provider.wont_be_nil
16
13
  end
17
- @metrobank.funds.each do |fund|
18
- @metrobank.value(fund[:name], fund[:type]).wont_be_nil
14
+ it "should get the current values of #{provider_klass.to_s}" do
15
+ @provider.funds.each do |fund|
16
+ @provider.value(fund[:name]).wont_be_empty
17
+ end
18
+ end
19
+ it "should get the value date of #{provider_klass.to_s}" do
20
+ assert @provider.value_at.is_a?(Date)
19
21
  end
20
22
  end
21
23
  end
metadata CHANGED
@@ -1,48 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navfund
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Marvin Baltazar
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-16 00:00:00.000000000 Z
11
+ date: 2015-04-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: nokogiri
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: '1.4'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: '1.4'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: '0.8'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: '0.8'
46
41
  description: Data scraper for Investment Fund Net Asset Values (NAVs)
47
42
  email:
48
43
  - marvin.baltazar@gmail.com
@@ -60,9 +55,15 @@ files:
60
55
  - lib/navfund/exceptions.rb
61
56
  - lib/navfund/navfund.rb
62
57
  - lib/navfund/provider.rb
58
+ - lib/navfund/providers/bdo_unibank.rb
59
+ - lib/navfund/providers/bpi.rb
63
60
  - lib/navfund/providers/metrobank.rb
64
61
  - lib/navfund/providers/philamlife.rb
62
+ - lib/navfund/providers/philippine_national_bank.rb
63
+ - lib/navfund/providers/security_bank.rb
65
64
  - lib/navfund/providers/sunlife.rb
65
+ - lib/navfund/providers/ucpb.rb
66
+ - lib/navfund/providers/union_bank.rb
66
67
  - lib/navfund/utils/require_relative.rb
67
68
  - lib/navfund/version.rb
68
69
  - navfund.gemspec
@@ -71,30 +72,30 @@ files:
71
72
  - test/lib/navfund/version_test.rb
72
73
  - test/test_helper.rb
73
74
  homepage: https://github.com/marvs/navfund
74
- licenses: []
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
75
78
  post_install_message:
76
79
  rdoc_options: []
77
80
  require_paths:
78
81
  - lib
79
82
  required_ruby_version: !ruby/object:Gem::Requirement
80
- none: false
81
83
  requirements:
82
- - - ! '>='
84
+ - - '>='
83
85
  - !ruby/object:Gem::Version
84
- version: '0'
86
+ version: 1.9.2
85
87
  required_rubygems_version: !ruby/object:Gem::Requirement
86
- none: false
87
88
  requirements:
88
- - - ! '>='
89
+ - - '>='
89
90
  - !ruby/object:Gem::Version
90
91
  version: '0'
91
92
  requirements: []
92
93
  rubyforge_project:
93
- rubygems_version: 1.8.25
94
+ rubygems_version: 2.2.2
94
95
  signing_key:
95
- specification_version: 3
96
- summary: Navfund is a ruby gem that fetches the values of the current NAVPU/NAVPS
97
- of several Banks/Providers of UITFs/Mutual Funds
96
+ specification_version: 4
97
+ summary: Navfund is a ruby gem that fetches the current NAVPU/NAVPS of UITFs/Mutual
98
+ Funds
98
99
  test_files:
99
100
  - test/lib/navfund/function_test.rb
100
101
  - test/lib/navfund/provider_test.rb