ambito 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/config/dollars.yml +16 -0
- data/exe/ambito +1 -1
- data/lib/ambito/cli.rb +23 -1
- data/lib/ambito/dollar.rb +27 -29
- data/lib/ambito/gateway.rb +30 -0
- data/lib/ambito/price.rb +27 -0
- data/lib/ambito/rate.rb +29 -0
- data/lib/ambito/variation.rb +37 -0
- data/lib/ambito/version.rb +1 -1
- data/lib/ambito.rb +8 -19
- metadata +7 -3
- data/sig/ambito.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d23be2cb4c6df3b9b39b52bca2a3f61f97d3ea0da79bee423df5e85e4387324e
|
4
|
+
data.tar.gz: d0b1156222d75af14749b9bfff6cc80550fcc0c20004337cfb7e0d478ac2d715
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdc8d2f6b7cb93b1af53f83d2f2c64a78f1198d260ec1e11a7ac8ef5b6e8b93affd564de405001f52e116264defd2253a60cb304e417a50caf7a4840a3460405
|
7
|
+
data.tar.gz: 4526159a7ac8282191e9f884e45efd713cde0e91857168eca569be72d24f4ba553d8dfdda67175cdba425be9c1c1597185f312ccb29b7ca887a49993a860685f
|
data/CHANGELOG.md
CHANGED
data/config/dollars.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
- !ruby/object:Ambito::Dollar
|
2
|
+
name: oficial
|
3
|
+
display: Oficial
|
4
|
+
endpoint: /dolar/oficial/variacion
|
5
|
+
- !ruby/object:Ambito::Dollar
|
6
|
+
name: informal
|
7
|
+
display: Informal
|
8
|
+
endpoint: /dolar/informal/variacion
|
9
|
+
- !ruby/object:Ambito::Dollar
|
10
|
+
name: mep
|
11
|
+
display: MEP
|
12
|
+
endpoint: /dolarrava/mep/variacion
|
13
|
+
- !ruby/object:Ambito::Dollar
|
14
|
+
name: cripto
|
15
|
+
display: Cripto
|
16
|
+
endpoint: /dolarcripto/variacion
|
data/exe/ambito
CHANGED
data/lib/ambito/cli.rb
CHANGED
@@ -1,7 +1,29 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
1
3
|
module Ambito
|
2
4
|
class CLI
|
5
|
+
def initialize(argv)
|
6
|
+
@argv = argv
|
7
|
+
end
|
8
|
+
|
3
9
|
def run
|
4
|
-
|
10
|
+
if options.any?
|
11
|
+
puts Ambito.rate(*options)
|
12
|
+
else
|
13
|
+
puts Ambito.rates
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def options
|
20
|
+
[].tap do |parsed_options|
|
21
|
+
OptionParser.new do |options|
|
22
|
+
options.on("-d", "--dollar DOLLAR", "Select the rate") do |dollar|
|
23
|
+
parsed_options << dollar
|
24
|
+
end
|
25
|
+
end.parse(@argv)
|
26
|
+
end
|
5
27
|
end
|
6
28
|
end
|
7
29
|
end
|
data/lib/ambito/dollar.rb
CHANGED
@@ -1,43 +1,41 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
1
3
|
module Ambito
|
2
4
|
class Dollar
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@buy = float(buy)
|
8
|
-
@sell = float(sell)
|
9
|
-
@type = TYPES.fetch(type.to_sym)
|
10
|
-
@variation = float(variation)
|
11
|
-
end
|
5
|
+
LIST = YAML.safe_load_file(
|
6
|
+
"#{__dir__}/../../config/dollars.yml",
|
7
|
+
permitted_classes: [Ambito::Dollar]
|
8
|
+
).freeze
|
12
9
|
|
13
|
-
|
14
|
-
(buy + sell) / 2
|
15
|
-
end
|
10
|
+
attr_reader :name, :display, :endpoint
|
16
11
|
|
17
|
-
def
|
18
|
-
|
12
|
+
def initialize(name:, display:, endpoint:)
|
13
|
+
@name = name
|
14
|
+
@display = display
|
15
|
+
@endpoint = endpoint
|
19
16
|
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
def rate
|
19
|
+
gateway = Gateway.new(endpoint:)
|
20
|
+
buy, sell, value, variation = gateway.get("compra", "venta", "valor", "variacion")
|
24
21
|
|
25
|
-
|
26
|
-
if variation.positive?
|
27
|
-
EMOJI[:up]
|
28
|
-
elsif variation.negative?
|
29
|
-
EMOJI[:down]
|
30
|
-
else
|
31
|
-
EMOJI[:equal]
|
32
|
-
end
|
22
|
+
Rate.new(dollar: self, buy:, sell:, value:, variation:)
|
33
23
|
end
|
34
24
|
|
35
|
-
def
|
36
|
-
|
25
|
+
def to_s
|
26
|
+
display
|
37
27
|
end
|
38
28
|
|
39
|
-
|
40
|
-
|
29
|
+
class << self
|
30
|
+
def all
|
31
|
+
LIST
|
32
|
+
end
|
33
|
+
|
34
|
+
def find(name)
|
35
|
+
LIST.find do |dollar|
|
36
|
+
dollar.name == String(name)
|
37
|
+
end
|
38
|
+
end
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Ambito
|
7
|
+
class Gateway
|
8
|
+
BASE_URL = "https://mercados.ambito.com"
|
9
|
+
|
10
|
+
def initialize(endpoint:)
|
11
|
+
@endpoint = endpoint
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(*)
|
15
|
+
JSON.parse(request).values_at(*)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :endpoint
|
21
|
+
|
22
|
+
def request
|
23
|
+
Net::HTTP.get(uri)
|
24
|
+
end
|
25
|
+
|
26
|
+
def uri
|
27
|
+
URI.join(BASE_URL, endpoint)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
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
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Ambito
|
2
|
+
class Rate
|
3
|
+
TRENDS = {up: "📈", down: "📉", equal: "📊"}.freeze
|
4
|
+
|
5
|
+
def initialize(dollar:, buy:, sell:, value:, variation:)
|
6
|
+
@dollar = dollar
|
7
|
+
@buy = Price[buy]
|
8
|
+
@sell = Price[sell]
|
9
|
+
@value = Price[value]
|
10
|
+
@variation = Variation[variation]
|
11
|
+
end
|
12
|
+
|
13
|
+
def average
|
14
|
+
Price[(buy + sell) / 2]
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"#{dollar}: #{price} #{variation.trend} #{variation}"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :dollar, :buy, :sell, :value, :variation
|
24
|
+
|
25
|
+
def price
|
26
|
+
value || average
|
27
|
+
end
|
28
|
+
end
|
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
@@ -1,32 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "net/http"
|
4
|
-
require "json"
|
5
3
|
require_relative "ambito/cli"
|
6
4
|
require_relative "ambito/dollar"
|
5
|
+
require_relative "ambito/gateway"
|
6
|
+
require_relative "ambito/price"
|
7
|
+
require_relative "ambito/rate"
|
8
|
+
require_relative "ambito/variation"
|
7
9
|
require_relative "ambito/version"
|
8
10
|
|
9
11
|
module Ambito
|
10
|
-
class Error < StandardError; end
|
11
|
-
|
12
|
-
DOLLARS = %w[
|
13
|
-
dolar/oficial
|
14
|
-
dolar/informal
|
15
|
-
dolarrava/mep
|
16
|
-
].freeze
|
17
|
-
|
18
12
|
class << self
|
19
|
-
def
|
20
|
-
|
21
|
-
res = JSON.parse(Net::HTTP.get(uri(dollar)))
|
22
|
-
type = dollar.split("/").last
|
23
|
-
buy, sell, variation = res.values_at("compra", "venta", "variacion")
|
24
|
-
Dollar.new(type:, buy:, sell:, variation:)
|
25
|
-
end
|
13
|
+
def rates
|
14
|
+
Dollar.all.map(&:rate)
|
26
15
|
end
|
27
16
|
|
28
|
-
def
|
29
|
-
|
17
|
+
def rate(dollar)
|
18
|
+
Dollar.find(dollar).rate
|
30
19
|
end
|
31
20
|
end
|
32
21
|
end
|
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.1
|
4
|
+
version: 0.2.1
|
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.
|
@@ -25,12 +25,16 @@ files:
|
|
25
25
|
- README.md
|
26
26
|
- Rakefile
|
27
27
|
- ambito.gemspec
|
28
|
+
- config/dollars.yml
|
28
29
|
- exe/ambito
|
29
30
|
- lib/ambito.rb
|
30
31
|
- lib/ambito/cli.rb
|
31
32
|
- lib/ambito/dollar.rb
|
33
|
+
- lib/ambito/gateway.rb
|
34
|
+
- lib/ambito/price.rb
|
35
|
+
- lib/ambito/rate.rb
|
36
|
+
- lib/ambito/variation.rb
|
32
37
|
- lib/ambito/version.rb
|
33
|
-
- sig/ambito.rbs
|
34
38
|
homepage: https://github.com/arzezak/ambito
|
35
39
|
licenses:
|
36
40
|
- MIT
|
data/sig/ambito.rbs
DELETED