Class: Ambito::Dollar

Inherits:
Object
  • Object
show all
Defined in:
lib/ambito/dollar.rb

Constant Summary collapse

LIST =
YAML.safe_load_file(
  "#{__dir__}/../../config/dollars.yml",
  permitted_classes: [Ambito::Dollar]
).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, display:, endpoint:) ⇒ Dollar

Returns a new instance of Dollar.



12
13
14
15
16
# File 'lib/ambito/dollar.rb', line 12

def initialize(name:, display:, endpoint:)
  @name = name
  @display = display
  @endpoint = endpoint
end

Instance Attribute Details

#display ⇒ Object (readonly)

Returns the value of attribute display.



10
11
12
# File 'lib/ambito/dollar.rb', line 10

def display
  @display
end

#endpoint ⇒ Object (readonly)

Returns the value of attribute endpoint.



10
11
12
# File 'lib/ambito/dollar.rb', line 10

def endpoint
  @endpoint
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/ambito/dollar.rb', line 10

def name
  @name
end

Class Method Details

.all ⇒ Object



30
31
32
# File 'lib/ambito/dollar.rb', line 30

def all
  LIST
end

.find(name) ⇒ Object



34
35
36
37
38
# File 'lib/ambito/dollar.rb', line 34

def find(name)
  LIST.find do |dollar|
    dollar.name == String(name)
  end
end

Instance Method Details

#rate ⇒ Object



18
19
20
21
22
23
# File 'lib/ambito/dollar.rb', line 18

def rate
  gateway = Gateway.new(endpoint:)
  buy, sell, value, variation = gateway.get("compra", "venta", "valor", "variacion")

  Rate.new(dollar: self, buy:, sell:, value:, variation:)
end

#to_s ⇒ Object



25
26
27
# File 'lib/ambito/dollar.rb', line 25

def to_s
  display
end