ambito 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/config/dollars.yml +14 -6
- data/lib/ambito/cli.rb +10 -4
- data/lib/ambito/dollar.rb +3 -7
- data/lib/ambito/price.rb +27 -0
- data/lib/ambito/rate.rb +10 -23
- data/lib/ambito/variation.rb +37 -0
- data/lib/ambito/version.rb +1 -1
- data/lib/ambito.rb +7 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 626b627c3f3718bde249aa3d225720dcf255d7533409f0b5fa099a1f5152edb5
|
4
|
+
data.tar.gz: cd38318ce750b2c7e594e79cad1aba342dc8dac0b89519a2bf1464d8ac464fd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2860ca43c23793ca8b82463dd326e7ff4a1bdbdd40ae67c085b843635d4cc40a4ffc25616e1279abde3ec34bbe5edf03e262aa7e3e27508bb5d4828b96517e13
|
7
|
+
data.tar.gz: abcbe303761efed98fc3924fb0865eee13a58c819c51a350698a345c3e0d025678a5a92f4f2e169c30ebd96ee05f68ba7e43816cb5443e02b944cf5c636dc912
|
data/CHANGELOG.md
CHANGED
data/config/dollars.yml
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
- !ruby/object:Ambito::Dollar
|
2
|
-
name:
|
3
|
-
display:
|
4
|
-
endpoint: /
|
2
|
+
name: ccl
|
3
|
+
display: CCL
|
4
|
+
endpoint: /dolarrava/cl/variacion
|
5
|
+
- !ruby/object:Ambito::Dollar
|
6
|
+
name: cripto
|
7
|
+
display: Cripto
|
8
|
+
endpoint: /dolarcripto/variacion
|
5
9
|
- !ruby/object:Ambito::Dollar
|
6
10
|
name: informal
|
7
11
|
display: Informal
|
@@ -11,6 +15,10 @@
|
|
11
15
|
display: MEP
|
12
16
|
endpoint: /dolarrava/mep/variacion
|
13
17
|
- !ruby/object:Ambito::Dollar
|
14
|
-
name:
|
15
|
-
display:
|
16
|
-
endpoint: /
|
18
|
+
name: oficial
|
19
|
+
display: Oficial
|
20
|
+
endpoint: /dolar/oficial/variacion
|
21
|
+
- !ruby/object:Ambito::Dollar
|
22
|
+
name: turista
|
23
|
+
display: Turista
|
24
|
+
endpoint: /dolarturista/variacion
|
data/lib/ambito/cli.rb
CHANGED
@@ -7,8 +7,11 @@ module Ambito
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def run
|
10
|
-
|
11
|
-
|
10
|
+
case options
|
11
|
+
in {dollar:}
|
12
|
+
puts Ambito.rate(dollar)
|
13
|
+
in {version: true}
|
14
|
+
puts Ambito::VERSION
|
12
15
|
else
|
13
16
|
puts Ambito.rates
|
14
17
|
end
|
@@ -17,10 +20,13 @@ module Ambito
|
|
17
20
|
private
|
18
21
|
|
19
22
|
def options
|
20
|
-
|
23
|
+
{}.tap do |parsed_options|
|
21
24
|
OptionParser.new do |options|
|
22
25
|
options.on("-d", "--dollar DOLLAR", "Select the rate") do |dollar|
|
23
|
-
parsed_options
|
26
|
+
parsed_options[:dollar] = dollar
|
27
|
+
end
|
28
|
+
options.on("-v", "--version", "Show version") do
|
29
|
+
parsed_options[:version] = true
|
24
30
|
end
|
25
31
|
end.parse(@argv)
|
26
32
|
end
|
data/lib/ambito/dollar.rb
CHANGED
@@ -3,7 +3,7 @@ require "yaml"
|
|
3
3
|
module Ambito
|
4
4
|
class Dollar
|
5
5
|
LIST = YAML.safe_load_file(
|
6
|
-
"
|
6
|
+
"#{__dir__}/../../config/dollars.yml",
|
7
7
|
permitted_classes: [Ambito::Dollar]
|
8
8
|
).freeze
|
9
9
|
|
@@ -17,9 +17,9 @@ module Ambito
|
|
17
17
|
|
18
18
|
def rate
|
19
19
|
gateway = Gateway.new(endpoint:)
|
20
|
-
buy, sell, variation = gateway.get("compra", "venta", "variacion")
|
20
|
+
buy, sell, value, variation = gateway.get("compra", "venta", "valor", "variacion")
|
21
21
|
|
22
|
-
Rate.new(dollar: self, buy:, sell:, variation:)
|
22
|
+
Rate.new(dollar: self, buy:, sell:, value:, variation:)
|
23
23
|
end
|
24
24
|
|
25
25
|
def to_s
|
@@ -36,10 +36,6 @@ module Ambito
|
|
36
36
|
dollar.name == String(name)
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
40
|
-
def where(name: nil)
|
41
|
-
name && find(name) || all
|
42
|
-
end
|
43
39
|
end
|
44
40
|
end
|
45
41
|
end
|
data/lib/ambito/price.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Ambito
|
2
|
+
class Price
|
3
|
+
attr_reader :quote
|
4
|
+
|
5
|
+
def initialize(quote)
|
6
|
+
@quote = parse(quote)
|
7
|
+
end
|
8
|
+
|
9
|
+
def +(other)
|
10
|
+
quote + other.quote
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse(quote)
|
14
|
+
String(quote).tr(",", ".").to_f
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
sprintf("$ %.2f" % quote)
|
19
|
+
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def [](quote)
|
23
|
+
quote && new(quote) || nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/ambito/rate.rb
CHANGED
@@ -2,41 +2,28 @@ module Ambito
|
|
2
2
|
class Rate
|
3
3
|
TRENDS = {up: "📈", down: "📉", equal: "📊"}.freeze
|
4
4
|
|
5
|
-
def initialize(dollar:, buy:, sell:, variation:)
|
5
|
+
def initialize(dollar:, buy:, sell:, value:, variation:)
|
6
6
|
@dollar = dollar
|
7
|
-
@buy =
|
8
|
-
@sell =
|
9
|
-
@
|
7
|
+
@buy = Price[buy]
|
8
|
+
@sell = Price[sell]
|
9
|
+
@value = Price[value]
|
10
|
+
@variation = Variation[variation]
|
10
11
|
end
|
11
12
|
|
12
13
|
def average
|
13
|
-
(buy + sell) / 2
|
14
|
+
Price[(buy + sell) / 2]
|
14
15
|
end
|
15
16
|
|
16
17
|
def to_s
|
17
|
-
"#{dollar}:
|
18
|
+
"#{dollar}: #{price} #{variation.trend} #{variation}"
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
21
22
|
|
22
|
-
attr_reader :dollar, :buy, :sell, :variation
|
23
|
+
attr_reader :dollar, :buy, :sell, :value, :variation
|
23
24
|
|
24
|
-
def
|
25
|
-
|
26
|
-
TRENDS[:up]
|
27
|
-
elsif variation.negative?
|
28
|
-
TRENDS[:down]
|
29
|
-
else
|
30
|
-
TRENDS[:equal]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def float(value)
|
35
|
-
value.tr(",", ".").to_f
|
36
|
-
end
|
37
|
-
|
38
|
-
def format(number)
|
39
|
-
sprintf("%.2f" % number)
|
25
|
+
def price
|
26
|
+
value || average
|
40
27
|
end
|
41
28
|
end
|
42
29
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Ambito
|
2
|
+
class Variation
|
3
|
+
TRENDS = {up: "📈", down: "📉", equal: "📊"}.freeze
|
4
|
+
|
5
|
+
attr_reader :value
|
6
|
+
|
7
|
+
def initialize(value)
|
8
|
+
@value = parse(value)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
sprintf("%.2f" % value) << "%"
|
13
|
+
end
|
14
|
+
|
15
|
+
def trend
|
16
|
+
if value.positive?
|
17
|
+
TRENDS[:up]
|
18
|
+
elsif value.negative?
|
19
|
+
TRENDS[:down]
|
20
|
+
else
|
21
|
+
TRENDS[:equal]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def parse(value)
|
28
|
+
value.tr(",", ".").to_f
|
29
|
+
end
|
30
|
+
|
31
|
+
class << self
|
32
|
+
def [](value)
|
33
|
+
new(value)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/ambito/version.rb
CHANGED
data/lib/ambito.rb
CHANGED
@@ -3,13 +3,19 @@
|
|
3
3
|
require_relative "ambito/cli"
|
4
4
|
require_relative "ambito/dollar"
|
5
5
|
require_relative "ambito/gateway"
|
6
|
+
require_relative "ambito/price"
|
6
7
|
require_relative "ambito/rate"
|
8
|
+
require_relative "ambito/variation"
|
7
9
|
require_relative "ambito/version"
|
8
10
|
|
9
11
|
module Ambito
|
10
12
|
class << self
|
11
13
|
def rates
|
12
|
-
Dollar.all.map
|
14
|
+
Dollar.all.map do |dollar|
|
15
|
+
Thread.new do
|
16
|
+
dollar.rate
|
17
|
+
end
|
18
|
+
end.map(&:value)
|
13
19
|
end
|
14
20
|
|
15
21
|
def rate(dollar)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ambito
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ariel Rzezak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Ruby gem for retrieving real-time USD exchange rates and financial
|
14
14
|
data.
|
@@ -31,7 +31,9 @@ files:
|
|
31
31
|
- lib/ambito/cli.rb
|
32
32
|
- lib/ambito/dollar.rb
|
33
33
|
- lib/ambito/gateway.rb
|
34
|
+
- lib/ambito/price.rb
|
34
35
|
- lib/ambito/rate.rb
|
36
|
+
- lib/ambito/variation.rb
|
35
37
|
- lib/ambito/version.rb
|
36
38
|
homepage: https://github.com/arzezak/ambito
|
37
39
|
licenses:
|