navfund 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,11 +10,11 @@ Add this line to your application's Gemfile:
10
10
 
11
11
  And then execute:
12
12
 
13
- $ bundle
13
+ bundle
14
14
 
15
15
  Or install it yourself as:
16
16
 
17
- $ gem install navfund
17
+ gem install navfund
18
18
 
19
19
  ## Usage
20
20
 
@@ -22,20 +22,36 @@ Get a list of supported Providers:
22
22
 
23
23
  Navfund::Providers
24
24
 
25
- Get supported funds for a specific Provider:
26
-
27
- Navfund::Sunlife::Funds
28
-
29
25
  Initialize a Provider's data:
30
26
 
31
27
  @sunlife = Navfund::Sunlife.new
32
-
28
+
29
+ To get a list of supported funds for a specific Provider:
30
+
31
+ Navfund::Sunlife::Funds
32
+ @sunlife.funds # if a provider is initialized
33
+
33
34
  Get the current NAVPU/NAVPS of a fund, by name:
34
35
 
35
36
  @sunlife.value("Bond Fund")
36
37
 
38
+ 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:
39
+
40
+ @sunlife.value("Bond Fund", :vul)
41
+
37
42
  A Navfund::Provider::InvalidFund will be raised if the specified fund is not supported or is invalid.
38
43
 
44
+ ## Testing
45
+
46
+ Install the minitest gem if its not already installed in your system
47
+
48
+ gem install minitest
49
+
50
+ Then run the tests (default rake task is the 'test' task):
51
+
52
+ rake test
53
+
54
+
39
55
  ## Contributing
40
56
 
41
57
  1. Fork it
data/Rakefile CHANGED
@@ -6,4 +6,6 @@ Rake::TestTask.new do |t|
6
6
  t.test_files = FileList['test/lib/navfund/*_test.rb']
7
7
  t.verbose = true
8
8
  end
9
+
10
+ desc "Run tests"
9
11
  task :default => :test
@@ -0,0 +1,19 @@
1
+ # Main module
2
+
3
+ module Navfund
4
+
5
+ class InvalidProvider < StandardError
6
+ def initialize(msg = "The provider you entered is not supported!")
7
+ super
8
+ end
9
+ end
10
+
11
+ class Provider
12
+ class InvalidFund < StandardError
13
+ def initialize(msg = "The fund name you entered is not supported!")
14
+ super
15
+ end
16
+ end
17
+ end
18
+
19
+ end
@@ -1,7 +1,6 @@
1
1
  # Main module
2
2
 
3
3
  module Navfund
4
- class InvalidProvider < StandardError; end
5
4
 
6
5
  #def self.scrape(url)
7
6
  # Providers.each do |scraper|
@@ -2,11 +2,23 @@
2
2
 
3
3
  module Navfund
4
4
  class Provider
5
- class InvalidFund < StandardError; end
6
5
 
7
6
  def scrape
8
7
  @document = open(@url).read
9
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)
12
+ end
10
13
  end
14
+
15
+ def self.strip_value(val)
16
+ val.strip.gsub('PHP', '').gsub('USD', '').strip
17
+ end
18
+
19
+ def valid_fund?(fund)
20
+ false
21
+ end
22
+
11
23
  end
12
24
  end
@@ -4,21 +4,34 @@ module Navfund
4
4
  class Sunlife < Provider
5
5
  # List of funds
6
6
  MAIN_URL = "http://www.sunlife.com.ph/philippines/Products+and+Services/Sun+Life+Prosperity+Funds?vgnLocale=en_CA"
7
+ VUL_URL = "http://www.sunlife.com.ph/philippines/Products+and+Services/VUL?vgnLocale=en_CA"
7
8
  Funds = ["Bond Fund", "Balanced Fund", "Equity Fund", "Money Market Fund", "GS Fund", "Dollar Advantage Fund", "Dollar Abundance Fund"]
8
9
 
9
10
  def initialize
10
11
  @url = MAIN_URL
12
+ @vul_url = VUL_URL
11
13
  self.scrape
12
- end
14
+ end
13
15
 
14
- def value(fund)
16
+ # Fetch the current value
17
+ # Some providers have a separate page for VUL funds, to force checking the VUL page,
18
+ # set the type to :vul, for example @sunlife.value("Bond Fund", :vul)
19
+ # It is possible that the same fund name is used for VUL and non-VUL funds so this is necessary
20
+ def value(fund, fund_type=nil)
15
21
  val = nil
22
+ # Set fund_type to nil if VUL page is not present
23
+ fund_type = nil if fund_type == :vul && @wrapped_vul_document.nil?
16
24
  if valid_fund?(fund)
17
- fname = @wrapped_document.search("[text()*='#{fund}']").first
25
+ source_document = (fund_type == :vul) ? @wrapped_vul_document : @wrapped_document
26
+ fname = source_document.search("[text()*='#{fund}']").first
18
27
  if fname
19
28
  fval = fname.parent.next_element rescue nil
20
- val = fval.text.strip.gsub('PHP', '').strip if fval
29
+ elsif @wrapped_vul_document && fund_type != :vul
30
+ # Search VUL page (if its not done before)
31
+ fname = @wrapped_vul_document.search("[text()*='#{fund}']").first
32
+ fval = fname.parent.next_element rescue nil
21
33
  end
34
+ val = Provider.strip_value(fval.text) if fval
22
35
  else
23
36
  raise InvalidFund
24
37
  end
@@ -28,5 +41,9 @@ module Navfund
28
41
  def valid_fund?(fund)
29
42
  Funds.include?(fund)
30
43
  end
44
+
45
+ def funds
46
+ Funds
47
+ end
31
48
  end
32
49
  end
@@ -1,3 +1,3 @@
1
1
  module Navfund
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/navfund.rb CHANGED
@@ -11,6 +11,7 @@ require "navfund/utils/require_relative"
11
11
  # Main files
12
12
  require "navfund/version"
13
13
  require "navfund/navfund"
14
+ require "navfund/exceptions"
14
15
  require "navfund/provider"
15
16
 
16
17
  # Providers
@@ -1,14 +1,5 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
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
4
+
14
5
  end
@@ -0,0 +1,20 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Navfund do
4
+ before do
5
+ @sunlife = Navfund::Sunlife.new
6
+ end
7
+ describe "when a provider is given" do
8
+ it "should get the provider object" do
9
+ @sunlife.wont_be_nil
10
+ end
11
+ it "should get the current value back in the response" do
12
+ Navfund::Sunlife::Funds.each do |fund|
13
+ @sunlife.value(fund).wont_be_nil
14
+ end
15
+ end
16
+ it "should get the current value back in the response when :vul is set" do
17
+ @sunlife.value("Bond Fund", :vul).wont_be_nil
18
+ end
19
+ end
20
+ 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.2
4
+ version: 0.0.3
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-13 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -56,6 +56,7 @@ files:
56
56
  - README.md
57
57
  - Rakefile
58
58
  - lib/navfund.rb
59
+ - lib/navfund/exceptions.rb
59
60
  - lib/navfund/navfund.rb
60
61
  - lib/navfund/provider.rb
61
62
  - lib/navfund/providers/metrobank.rb
@@ -64,6 +65,7 @@ files:
64
65
  - lib/navfund/version.rb
65
66
  - navfund.gemspec
66
67
  - test/lib/navfund/function_test.rb
68
+ - test/lib/navfund/provider_test.rb
67
69
  - test/lib/navfund/version_test.rb
68
70
  - test/test_helper.rb
69
71
  homepage: https://github.com/marvs/navfund
@@ -93,5 +95,6 @@ summary: Navfund is a ruby gem that fetches the values of the current NAVPU/NAVP
93
95
  of several Banks/Providers of UITFs/Mutual Funds
94
96
  test_files:
95
97
  - test/lib/navfund/function_test.rb
98
+ - test/lib/navfund/provider_test.rb
96
99
  - test/lib/navfund/version_test.rb
97
100
  - test/test_helper.rb