navfund 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +45 -0
- data/Rakefile +9 -0
- data/lib/navfund/navfund.rb +13 -0
- data/lib/navfund/provider.rb +12 -0
- data/lib/navfund/providers/metrobank.rb +15 -0
- data/lib/navfund/providers/sunlife.rb +32 -0
- data/lib/navfund/utils/require_relative.rb +18 -0
- data/lib/navfund/version.rb +3 -0
- data/lib/navfund.rb +22 -0
- data/navfund.gemspec +21 -0
- data/test/lib/navfund/function_test.rb +14 -0
- data/test/lib/navfund/version_test.rb +7 -0
- data/test/test_helper.rb +2 -0
- metadata +98 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Marvin Baltazar
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Navfund
|
2
|
+
|
3
|
+
Navfund is a ruby gem that fetches the values of the current NAVPU/NAVPS of several Banks/Providers of UITFs/Mutual Funds in the Philippines. Currently it only supports Sunlife NAVPS.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'navfund'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install navfund
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Get a list of supported Providers:
|
22
|
+
|
23
|
+
Navfund::Providers
|
24
|
+
|
25
|
+
Get supported funds for a specific Provider:
|
26
|
+
|
27
|
+
Navfund::Sunlife::Funds
|
28
|
+
|
29
|
+
Initialize a Provider's data:
|
30
|
+
|
31
|
+
@sunlife = Navfund::Sunlife.new
|
32
|
+
|
33
|
+
Get the current NAVPU/NAVPS of a fund, by name:
|
34
|
+
|
35
|
+
@sunlife.value("Bond Fund")
|
36
|
+
|
37
|
+
A Navfund::Provider::InvalidFund will be raised if the specified fund is not supported or is invalid.
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Sun Life Financial
|
2
|
+
|
3
|
+
module Navfund
|
4
|
+
class Sunlife < Provider
|
5
|
+
# List of funds
|
6
|
+
MAIN_URL = "http://www.sunlife.com.ph/philippines/Products+and+Services/Sun+Life+Prosperity+Funds?vgnLocale=en_CA"
|
7
|
+
Funds = ["Bond Fund", "Balanced Fund", "Equity Fund", "Money Market Fund", "GS Fund", "Dollar Advantage Fund", "Dollar Abundance Fund"]
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@url = MAIN_URL
|
11
|
+
self.scrape
|
12
|
+
end
|
13
|
+
|
14
|
+
def value(fund)
|
15
|
+
val = nil
|
16
|
+
if valid_fund?(fund)
|
17
|
+
fname = @wrapped_document.search("[text()*='#{fund}']").first
|
18
|
+
if fname
|
19
|
+
fval = fname.parent.next_element rescue nil
|
20
|
+
val = fval.text.strip.gsub('PHP', '').strip if fval
|
21
|
+
end
|
22
|
+
else
|
23
|
+
raise InvalidFund
|
24
|
+
end
|
25
|
+
val
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid_fund?(fund)
|
29
|
+
Funds.include?(fund)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copypasta from https://github.com/appoxy/aws/blob/master/lib/awsbase/require_relative.rb
|
2
|
+
|
3
|
+
unless Kernel.respond_to?(:require_relative)
|
4
|
+
module Kernel
|
5
|
+
def require_relative(path)
|
6
|
+
desired_path = File.expand_path('../' + path.to_str, caller[0])
|
7
|
+
shortest = desired_path
|
8
|
+
$:.each do |path|
|
9
|
+
path += '/'
|
10
|
+
if desired_path.index(path) == 0
|
11
|
+
candidate = desired_path.sub(path, '')
|
12
|
+
shortest = candidate if candidate.size < shortest.size
|
13
|
+
end
|
14
|
+
end
|
15
|
+
require shortest
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/navfund.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
# Add current directory to load paths
|
5
|
+
main_dir = File.dirname(__FILE__)
|
6
|
+
$:.unshift(main_dir) unless $:.include?(main_dir)
|
7
|
+
|
8
|
+
# Utilities
|
9
|
+
require "navfund/utils/require_relative"
|
10
|
+
|
11
|
+
# Main files
|
12
|
+
require "navfund/version"
|
13
|
+
require "navfund/navfund"
|
14
|
+
require "navfund/provider"
|
15
|
+
|
16
|
+
# Providers
|
17
|
+
require "navfund/providers/metrobank"
|
18
|
+
require "navfund/providers/sunlife"
|
19
|
+
|
20
|
+
module Navfund
|
21
|
+
Providers = [Metrobank, Sunlife]
|
22
|
+
end
|
data/navfund.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/navfund/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "navfund"
|
6
|
+
gem.version = Navfund::VERSION
|
7
|
+
gem.platform = Gem::Platform::RUBY
|
8
|
+
gem.authors = ["Marvin Baltazar"]
|
9
|
+
gem.email = ["marvin.baltazar@gmail.com"]
|
10
|
+
gem.description = %q{Data scraper for Philippine-based Investment Fund Net Asset Values (NAVs)}
|
11
|
+
gem.summary = %q{This gem allows you to fetch the latest NAVPU/NAVPS from Philippine-based Investment Funds. In the future, this gem will include support for other countries as well!}
|
12
|
+
gem.homepage = "http://mambin.com"
|
13
|
+
|
14
|
+
gem.add_runtime_dependency "nokogiri"
|
15
|
+
gem.add_development_dependency "rake"
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($\)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Navfund do
|
4
|
+
before do
|
5
|
+
@fund = Navfund::Metrobank.fund("Equity")
|
6
|
+
end
|
7
|
+
it "should get the fund object" do
|
8
|
+
@fund.should_not be_blank
|
9
|
+
STDERR.puts "<p>#{@fund.inspect}</p>"
|
10
|
+
end
|
11
|
+
it "should get the current navpu back in the response" do
|
12
|
+
@fund.value.should_not be_blank
|
13
|
+
end
|
14
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: navfund
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marvin Baltazar
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Data scraper for Philippine-based Investment Fund Net Asset Values (NAVs)
|
47
|
+
email:
|
48
|
+
- marvin.baltazar@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/navfund.rb
|
59
|
+
- lib/navfund/navfund.rb
|
60
|
+
- lib/navfund/provider.rb
|
61
|
+
- lib/navfund/providers/metrobank.rb
|
62
|
+
- lib/navfund/providers/sunlife.rb
|
63
|
+
- lib/navfund/utils/require_relative.rb
|
64
|
+
- lib/navfund/version.rb
|
65
|
+
- navfund.gemspec
|
66
|
+
- test/lib/navfund/function_test.rb
|
67
|
+
- test/lib/navfund/version_test.rb
|
68
|
+
- test/test_helper.rb
|
69
|
+
homepage: http://mambin.com
|
70
|
+
licenses: []
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.8.21
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: This gem allows you to fetch the latest NAVPU/NAVPS from Philippine-based
|
93
|
+
Investment Funds. In the future, this gem will include support for other countries
|
94
|
+
as well!
|
95
|
+
test_files:
|
96
|
+
- test/lib/navfund/function_test.rb
|
97
|
+
- test/lib/navfund/version_test.rb
|
98
|
+
- test/test_helper.rb
|