dolarblue 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +7 -16
- data/bin/cardblue +7 -0
- data/bin/dolarblue +1 -1
- data/lib/dolarblue.rb +8 -0
- data/lib/dolarblue/instance_methods.rb +28 -13
- data/lib/dolarblue/version.rb +1 -1
- data/spec/dolarblue_spec.rb +51 -13
- data/spec/inflector_spec.rb +28 -0
- data/spec/spec_helper.rb +15 -8
- metadata +8 -5
- data/spec/blue_spec.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05b7c9859ba4b1c5081f33dd8595dc3b3c869dc7
|
4
|
+
data.tar.gz: 2e95fc8add7d2965c59d0fe596b2e521c8372be7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8344dfa4f5719517033033efdef333a54c6328bcc62fcd5d60aee5dd4c7d57823695596d0fbb6ee9f532b3196d561a424a7e9c7312ae61fef95bb34ea570d3c
|
7
|
+
data.tar.gz: 9da662bc43b017e650f8dd48e97f1ec0a7bf411774806dbc5183b92dbf6448f5fd174a0311a5c9a59d5ae98443a7b3b47e20b759c30690fe7c8a9b4d27275f5b
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.0
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
## [In git](https://github.com/elgalu/dolarblue/compare/v0.4.0...HEAD)
|
2
2
|
|
3
|
+
### New Features
|
4
|
+
* n/a
|
5
|
+
|
6
|
+
### Bug Fixes
|
3
7
|
* n/a
|
4
8
|
|
9
|
+
### Chores
|
10
|
+
* Added more specs for increased coverage. (Leo Gallucci)
|
11
|
+
* Simplified and improved vcr cassettes usage. (Leo Gallucci)
|
12
|
+
* Added specs to test the CLI and went back to successful 100% coverage. (Leo Gallucci)
|
13
|
+
|
5
14
|
## [v0.4.0](https://github.com/elgalu/dolarblue/tree/v0.4.0)
|
6
15
|
|
7
16
|
### New Features
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dolarblue (0.4.
|
4
|
+
dolarblue (0.4.1.dev)
|
5
5
|
configatron (>= 3.0.0.rc2)
|
6
6
|
nokogiri (>= 1.6.1)
|
7
7
|
|
@@ -23,40 +23,34 @@ GEM
|
|
23
23
|
crack (0.4.1)
|
24
24
|
safe_yaml (~> 0.9.0)
|
25
25
|
debug_inspector (0.0.2)
|
26
|
-
debugger (1.6.
|
26
|
+
debugger (1.6.5)
|
27
27
|
columnize (>= 0.3.1)
|
28
28
|
debugger-linecache (~> 1.2.0)
|
29
|
-
debugger-ruby_core_source (~> 1.
|
29
|
+
debugger-ruby_core_source (~> 1.3.1)
|
30
30
|
debugger-linecache (1.2.0)
|
31
|
-
debugger-ruby_core_source (1.
|
31
|
+
debugger-ruby_core_source (1.3.1)
|
32
32
|
diff-lcs (1.2.5)
|
33
33
|
docile (1.1.1)
|
34
|
-
ffi (1.9.3-java)
|
35
34
|
method_source (0.8.2)
|
36
35
|
mime-types (2.0)
|
37
36
|
mini_portile (0.5.2)
|
38
|
-
multi_json (1.8.
|
37
|
+
multi_json (1.8.3)
|
39
38
|
nokogiri (1.6.1)
|
40
39
|
mini_portile (~> 0.5.0)
|
41
40
|
pry (0.9.12.4)
|
42
41
|
coderay (~> 1.0)
|
43
42
|
method_source (~> 0.8)
|
44
43
|
slop (~> 3.4)
|
45
|
-
pry (0.9.12.4-java)
|
46
|
-
coderay (~> 1.0)
|
47
|
-
method_source (~> 0.8)
|
48
|
-
slop (~> 3.4)
|
49
|
-
spoon (~> 0.0)
|
50
44
|
pry-debugger (0.2.2)
|
51
45
|
debugger (~> 1.3)
|
52
46
|
pry (~> 0.9.10)
|
53
|
-
pry-doc (0.
|
47
|
+
pry-doc (0.5.1)
|
54
48
|
pry (>= 0.9)
|
55
49
|
yard (>= 0.8)
|
56
50
|
pry-stack_explorer (0.4.9.1)
|
57
51
|
binding_of_caller (>= 0.7)
|
58
52
|
pry (>= 0.9.11)
|
59
|
-
rake (10.1.
|
53
|
+
rake (10.1.1)
|
60
54
|
redcarpet (3.0.0)
|
61
55
|
rest-client (1.6.7)
|
62
56
|
mime-types (>= 1.16)
|
@@ -76,8 +70,6 @@ GEM
|
|
76
70
|
simplecov-html (~> 0.8.0)
|
77
71
|
simplecov-html (0.8.0)
|
78
72
|
slop (3.4.7)
|
79
|
-
spoon (0.0.4)
|
80
|
-
ffi
|
81
73
|
term-ansicolor (1.2.2)
|
82
74
|
tins (~> 0.8)
|
83
75
|
thor (0.18.1)
|
@@ -89,7 +81,6 @@ GEM
|
|
89
81
|
yard (0.8.7.3)
|
90
82
|
|
91
83
|
PLATFORMS
|
92
|
-
java
|
93
84
|
ruby
|
94
85
|
|
95
86
|
DEPENDENCIES
|
data/bin/cardblue
ADDED
data/bin/dolarblue
CHANGED
data/lib/dolarblue.rb
CHANGED
@@ -12,5 +12,13 @@ class Dolarblue
|
|
12
12
|
def get_output
|
13
13
|
new.update!.output
|
14
14
|
end
|
15
|
+
|
16
|
+
# Returns all the dollar card exchange 'Blue' vs 'Card' info
|
17
|
+
# suitable for user printing analysis
|
18
|
+
#
|
19
|
+
# @return [String] with all dollar exchange 'Blue' vs 'Card' values
|
20
|
+
def get_cardblue_output
|
21
|
+
new.update!(false).cardblue_output
|
22
|
+
end
|
15
23
|
end
|
16
24
|
end
|
@@ -18,25 +18,25 @@ class Dolarblue
|
|
18
18
|
@blue = Blue.new
|
19
19
|
@official = Official.new
|
20
20
|
@card = Card.new
|
21
|
-
@output = nil
|
22
21
|
self
|
23
22
|
end
|
24
23
|
|
25
24
|
# Connect to the source and retrieve dollar exchange values
|
26
25
|
#
|
26
|
+
# @param log [Boolean] weather to show log standard outputs or not
|
27
|
+
#
|
27
28
|
# @return (see #initialize)
|
28
|
-
def update!
|
29
|
-
@output = ''
|
29
|
+
def update!(log=true)
|
30
30
|
base_url = @config.base_url
|
31
31
|
fail ArgumentError, "Need base_url configuration to know where to web-scrape from. Current value: #{base_url}" if base_url.empty?
|
32
32
|
|
33
|
-
log "Obtaining latest AR$ vs US$ exchange values..."
|
33
|
+
log "Obtaining latest AR$ vs US$ exchange values..." if log
|
34
34
|
html_file = open(base_url)
|
35
35
|
|
36
|
-
log "Parsing values..."
|
36
|
+
log "Parsing values..." if log
|
37
37
|
parse_values Nokogiri::HTML(html_file)
|
38
38
|
|
39
|
-
log "\nDone: #{Time.now.localtime}\n"
|
39
|
+
log "\nDone: #{Time.now.localtime}\n" if log
|
40
40
|
self
|
41
41
|
end
|
42
42
|
|
@@ -61,7 +61,6 @@ class Dolarblue
|
|
61
61
|
# @return [String] the output with dollar exchange information
|
62
62
|
def output
|
63
63
|
<<-OUTPUT
|
64
|
-
#{@output}
|
65
64
|
#{@official.output}
|
66
65
|
#{@card.output}
|
67
66
|
#{@blue.output}
|
@@ -74,6 +73,27 @@ Information source:
|
|
74
73
|
OUTPUT
|
75
74
|
end
|
76
75
|
|
76
|
+
# Output string to be used by the binary `cardblue`
|
77
|
+
#
|
78
|
+
# @return [String] the output with card/dollar exchange info
|
79
|
+
def cardblue_output
|
80
|
+
n = 27
|
81
|
+
bol_discount = 0.97
|
82
|
+
card_delay_add = 1.01
|
83
|
+
payo_discount = 0.967
|
84
|
+
net_ticket = 375
|
85
|
+
sell_ticket = 396.2
|
86
|
+
|
87
|
+
real = (@blue.sell * bol_discount).round(2)
|
88
|
+
profit = n * (real * net_ticket * payo_discount - @card.sell * card_delay_add * sell_ticket)
|
89
|
+
now = Time.now.localtime.strftime("%H:%M:%S")
|
90
|
+
|
91
|
+
<<-OUTPUT
|
92
|
+
Card[#{@card.sell_output}] Blue[#{@blue.sell_output}] Gap[#{gap_card_percent}%] #{now}
|
93
|
+
#{profit.round(0)}=#{n}*(#{real}*#{net_ticket}*#{payo_discount}-#{@card.sell}*#{card_delay_add}*#{sell_ticket})
|
94
|
+
OUTPUT
|
95
|
+
end
|
96
|
+
|
77
97
|
private
|
78
98
|
|
79
99
|
# Parse dollar related values using the XPath configured
|
@@ -88,15 +108,10 @@ Information source:
|
|
88
108
|
end
|
89
109
|
|
90
110
|
# Poor man's logger to keep user updated with http get activity
|
91
|
-
# while allowing to buffer the string while in RSpec test mode
|
92
111
|
#
|
93
112
|
# @param msg [String] the message to print or buffer
|
94
113
|
def log(msg)
|
95
|
-
|
96
|
-
@output << msg
|
97
|
-
else
|
98
|
-
print msg
|
99
|
-
end
|
114
|
+
$stdout.print msg
|
100
115
|
end
|
101
116
|
|
102
117
|
end
|
data/lib/dolarblue/version.rb
CHANGED
data/spec/dolarblue_spec.rb
CHANGED
@@ -1,22 +1,60 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
CLI_MATCHERS = [
|
4
|
+
/^Obtaining latest/,
|
5
|
+
/Parsing values/,
|
6
|
+
/^Done: \d+/
|
7
|
+
]
|
8
|
+
|
9
|
+
values = %q{\d+\.\d+\s+\/\s+\d+\.\d+}
|
10
|
+
start = '- '
|
11
|
+
OUTPUT_MATCHERS = [
|
12
|
+
/^#{start}Dollar Official.*#{values}$/,
|
13
|
+
/^#{start}Dollar Card.*n\/a\s+\/\s+\d+\.\d+$/,
|
14
|
+
/^#{start}Dollar Blue.*#{values}$/,
|
15
|
+
/^#{start}Gap card/,
|
16
|
+
/^#{start}Gap official/,
|
17
|
+
/^Information source:$/
|
18
|
+
]
|
19
|
+
|
20
|
+
describe Dolarblue do
|
21
|
+
before(:each) do
|
22
|
+
# Save and capture standard output
|
23
|
+
@saved_stdout = $stdout
|
24
|
+
$stdout = StringIO.new
|
25
|
+
end
|
26
|
+
|
27
|
+
after(:each) do
|
28
|
+
# Restore standard output
|
29
|
+
$stdout = @saved_stdout
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'CLI' do
|
33
|
+
let(:path) { File.expand_path('../../bin/dolarblue', __FILE__) }
|
34
|
+
|
35
|
+
it 'should print out status information about querying base_url and parsing data' do
|
36
|
+
(CLI_MATCHERS).each do |regex|
|
37
|
+
$stdout.should_receive(:print).with(regex)
|
38
|
+
end
|
39
|
+
load path
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should puts all the dollar exchange values' do
|
43
|
+
load path
|
44
|
+
(OUTPUT_MATCHERS).each do |regex|
|
45
|
+
expect($stdout.string).to match(regex)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
4
49
|
|
5
|
-
describe Dolarblue, vcr: vcr_options do
|
6
50
|
context 'Class Methods' do
|
7
51
|
subject { Dolarblue }
|
8
52
|
|
9
|
-
it 'should return all the dollar exchange Blue/Official/Card values and percentiles
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
values = %q{\d+\.\d+\s+\/\s+\d+\.\d+}
|
14
|
-
expect(subject.get_output).to match(/Official.*#{values}/)
|
15
|
-
expect(subject.get_output).to match(/Card.*n\/a\s+\/\s+\d+\.\d+/)
|
16
|
-
expect(subject.get_output).to match(/Blue.*#{values}/)
|
17
|
-
expect(subject.get_output).to match(/Gap card/)
|
18
|
-
expect(subject.get_output).to match(/Gap official/)
|
19
|
-
expect(subject.get_output).to match(/Information source/)
|
53
|
+
it 'should return all the dollar exchange Blue/Official/Card values and percentiles' do
|
54
|
+
OUTPUT_MATCHERS.each do |regex|
|
55
|
+
expect(subject.get_output).to match(regex)
|
56
|
+
end
|
20
57
|
end
|
21
58
|
end
|
59
|
+
|
22
60
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dolarblue::Inflector do
|
4
|
+
|
5
|
+
subject { Dolarblue::Inflector }
|
6
|
+
|
7
|
+
it 'demodulizes simple 1-level unnested classes' do
|
8
|
+
expect(subject.demodulize('Account')).to eq('Account')
|
9
|
+
expect(subject.demodulize('Inflections')).to eq('Inflections')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'demodulizes larger 3-levels nested classes' do
|
13
|
+
expect(subject.demodulize('MyApplication::Billing::Account')).to eq('Account')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'demodulizes 2-levels nested classes' do
|
17
|
+
expect(subject.demodulize('Dolarblue::Card')).to eq('Card')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'demodulizes larger 4-levels nested classes' do
|
21
|
+
expect(subject.demodulize('ActiveRecord::CoreExtensions::String::Inflections')).to eq('Inflections')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'demodulizes empty unnested string' do
|
25
|
+
expect(subject.demodulize('')).to eq('')
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,14 +11,6 @@ end
|
|
11
11
|
|
12
12
|
require 'dolarblue'
|
13
13
|
|
14
|
-
require 'vcr' # gem 'vcr'
|
15
|
-
|
16
|
-
VCR.configure do |c|
|
17
|
-
c.cassette_library_dir = 'spec/cassettes'
|
18
|
-
c.hook_into :webmock
|
19
|
-
c.configure_rspec_metadata!
|
20
|
-
end
|
21
|
-
|
22
14
|
# Require this file using `require "spec_helper"` within each of your specs
|
23
15
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
24
16
|
RSpec.configure do |config|
|
@@ -30,3 +22,18 @@ RSpec.configure do |config|
|
|
30
22
|
c.syntax = :expect # disable `should` syntax http://goo.gl/BGxqP
|
31
23
|
end
|
32
24
|
end
|
25
|
+
|
26
|
+
require 'vcr' # gem 'vcr'
|
27
|
+
|
28
|
+
VCR.configure do |c|
|
29
|
+
c.cassette_library_dir = 'spec/cassettes'
|
30
|
+
c.hook_into :webmock
|
31
|
+
c.default_cassette_options = { allow_playback_repeats: true, record: :new_episodes }
|
32
|
+
c.configure_rspec_metadata!
|
33
|
+
end
|
34
|
+
|
35
|
+
# VCR + Rspec integration
|
36
|
+
RSpec.configure do |config|
|
37
|
+
config.before(:suite) { VCR.insert_cassette 'Dolarblue' }
|
38
|
+
config.after(:suite) { VCR.eject_cassette }
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dolarblue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leo Gallucci
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: configatron
|
@@ -151,6 +151,7 @@ description: Query Argentine Peso vs US$ exchange values with particular interes
|
|
151
151
|
email:
|
152
152
|
- elgalu3@gmail.com
|
153
153
|
executables:
|
154
|
+
- cardblue
|
154
155
|
- dolarblue
|
155
156
|
extensions: []
|
156
157
|
extra_rdoc_files: []
|
@@ -167,6 +168,7 @@ files:
|
|
167
168
|
- LICENSE.md
|
168
169
|
- README.md
|
169
170
|
- Rakefile
|
171
|
+
- bin/cardblue
|
170
172
|
- bin/dolarblue
|
171
173
|
- config/xpaths.yml
|
172
174
|
- dolarblue.gemspec
|
@@ -179,9 +181,9 @@ files:
|
|
179
181
|
- lib/dolarblue/official.rb
|
180
182
|
- lib/dolarblue/version.rb
|
181
183
|
- lib/dolarblue/xchange.rb
|
182
|
-
- spec/blue_spec.rb
|
183
184
|
- spec/cassettes/.keep
|
184
185
|
- spec/dolarblue_spec.rb
|
186
|
+
- spec/inflector_spec.rb
|
185
187
|
- spec/spec_helper.rb
|
186
188
|
homepage: https://github.com/elgalu/dolarblue
|
187
189
|
licenses:
|
@@ -203,13 +205,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
205
|
version: 1.8.25
|
204
206
|
requirements: []
|
205
207
|
rubyforge_project:
|
206
|
-
rubygems_version: 2.
|
208
|
+
rubygems_version: 2.2.0
|
207
209
|
signing_key:
|
208
210
|
specification_version: 4
|
209
211
|
summary: Query Argentine Peso vs US$ exchange values with particular interest in official
|
210
212
|
vs. street (blue) reference prices.
|
211
213
|
test_files:
|
212
|
-
- spec/blue_spec.rb
|
213
214
|
- spec/cassettes/.keep
|
214
215
|
- spec/dolarblue_spec.rb
|
216
|
+
- spec/inflector_spec.rb
|
215
217
|
- spec/spec_helper.rb
|
218
|
+
has_rdoc:
|