rupee 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/rupee/quote.rb +29 -2
  2. data/lib/rupee/version.rb +1 -1
  3. metadata +49 -44
data/lib/rupee/quote.rb CHANGED
@@ -12,8 +12,8 @@ module Rupee
12
12
  #
13
13
  # wfc = Rupee::Quote.new("WFC")
14
14
  #
15
- # wfc.get :price, :change, :pct_change
16
- # #=> {:price=>24.96, :change=>0.17, :pct_change =>0.686}
15
+ # wfc.get :price, :change, :pct_chg
16
+ # #=> {:price=>24.96, :change=>0.17, :pct_chg =>0.686}
17
17
  #
18
18
  # wfc.price
19
19
  # #=> 24.96
@@ -93,6 +93,17 @@ module Rupee
93
93
  end
94
94
  end
95
95
 
96
+ # The bid-ask spread
97
+ def bid_ask
98
+ b, a = bid, ask
99
+
100
+ if b.nil? || a.nil?
101
+ nil
102
+ else
103
+ (a - b).round precision(a, b)
104
+ end
105
+ end
106
+
96
107
  def frequency=(x) # :nodoc:
97
108
  @next_pull += (x - @frequency)
98
109
  @frequency = x
@@ -111,5 +122,21 @@ module Rupee
111
122
  result
112
123
  end
113
124
  end
125
+
126
+ # Scans the values provided for the number with the greatest number of
127
+ # decimal places, then returns that number of decimal places
128
+ #
129
+ # precision 0, 1.5, 2.25, 3 #=> 2
130
+ def precision(*values)
131
+ values.map do |value|
132
+ temp = value.to_s.split(".")
133
+
134
+ if temp.length > 1
135
+ temp[1].length
136
+ else
137
+ 0
138
+ end
139
+ end.max
140
+ end
114
141
  end
115
142
  end
data/lib/rupee/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Rupee
2
2
  # The current version
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
metadata CHANGED
@@ -1,58 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rupee
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.2.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Bryan McKelvey
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-29 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2011-09-29 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: bundler
16
- requirement: &70293110 !ruby/object:Gem::Requirement
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
17
19
  none: false
18
- requirements:
20
+ requirements:
19
21
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '1.0'
22
+ - !ruby/object:Gem::Version
23
+ version: "1.0"
22
24
  type: :development
23
- prerelease: false
24
- version_requirements: *70293110
25
- - !ruby/object:Gem::Dependency
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
26
27
  name: rspec
27
- requirement: &70292860 !ruby/object:Gem::Requirement
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
28
30
  none: false
29
- requirements:
31
+ requirements:
30
32
  - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '2.0'
33
+ - !ruby/object:Gem::Version
34
+ version: "2.0"
33
35
  type: :development
34
- prerelease: false
35
- version_requirements: *70292860
36
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
37
38
  name: sdoc
38
- requirement: &70292600 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
39
41
  none: false
40
- requirements:
42
+ requirements:
41
43
  - - ~>
42
- - !ruby/object:Gem::Version
43
- version: '0.3'
44
+ - !ruby/object:Gem::Version
45
+ version: "0.3"
44
46
  type: :development
45
- prerelease: false
46
- version_requirements: *70292600
47
- description: ! " rupee aims to provide user-friendly tools for
48
- use in\n financial gems and applications.\n"
49
- email:
47
+ version_requirements: *id003
48
+ description: " rupee aims to provide user-friendly tools for use in\n financial gems and applications.\n"
49
+ email:
50
50
  - bryan.mckelvey@gmail.com
51
51
  executables: []
52
- extensions:
52
+
53
+ extensions:
53
54
  - ext/rupee/extconf.rb
54
55
  extra_rdoc_files: []
55
- files:
56
+
57
+ files:
56
58
  - .autotest
57
59
  - .gitignore
58
60
  - .rspec
@@ -85,30 +87,33 @@ files:
85
87
  - test_rubies
86
88
  homepage: https://github.com/brymck/rupee
87
89
  licenses: []
90
+
88
91
  post_install_message:
89
92
  rdoc_options: []
90
- require_paths:
93
+
94
+ require_paths:
91
95
  - lib
92
96
  - ext
93
- required_ruby_version: !ruby/object:Gem::Requirement
97
+ required_ruby_version: !ruby/object:Gem::Requirement
94
98
  none: false
95
- requirements:
96
- - - ! '>='
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
104
  none: false
101
- requirements:
102
- - - ! '>='
103
- - !ruby/object:Gem::Version
104
- version: '0'
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: "0"
105
109
  requirements: []
110
+
106
111
  rubyforge_project: rupee
107
112
  rubygems_version: 1.8.10
108
113
  signing_key:
109
114
  specification_version: 3
110
115
  summary: Financial tools for Ruby
111
- test_files:
116
+ test_files:
112
117
  - spec/native/bond_spec.rb
113
118
  - spec/native/future_spec.rb
114
119
  - spec/native/option_spec.rb