navfund 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in navfund.gemspec
4
+ gemspec
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,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'lib/navfund'
6
+ t.test_files = FileList['test/lib/navfund/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+ task :default => :test
@@ -0,0 +1,13 @@
1
+ # Main module
2
+
3
+ module Navfund
4
+ class InvalidProvider < StandardError; end
5
+
6
+ #def self.scrape(url)
7
+ # Providers.each do |scraper|
8
+ # return scraper.new(url) if scraper.can_scrape?(url)
9
+ # end
10
+ # raise InvalidProvider
11
+ #end
12
+
13
+ end
@@ -0,0 +1,12 @@
1
+ # Provider class, where all banks/providers inherit
2
+
3
+ module Navfund
4
+ class Provider
5
+ class InvalidFund < StandardError; end
6
+
7
+ def scrape
8
+ @document = open(@url).read
9
+ @wrapped_document = Nokogiri::HTML(@document)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ # Metrobank
2
+
3
+ module Navfund
4
+ class Metrobank < Provider
5
+ # List of funds
6
+ MAIN_URL = "http://www.metrobank.com.ph/trust_product.asp"
7
+ Funds = [""]
8
+
9
+ def initialize
10
+ @url = MAIN_URL
11
+ self.scrape
12
+ end
13
+
14
+ end
15
+ end
@@ -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
@@ -0,0 +1,3 @@
1
+ module Navfund
2
+ VERSION = "0.0.1"
3
+ 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
@@ -0,0 +1,7 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Navfund do
4
+ it "must be defined" do
5
+ Navfund::VERSION.wont_be_nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ require 'minitest/autorun'
2
+ require File.expand_path('../../lib/navfund.rb', __FILE__)
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