Module: IEX::Resources::Base

Defined in:
lib/iex/resources/base.rb

Class Method Summary collapse

Class Method Details

.float_to_percentage(float_number) ⇒ Object


12
13
14
15
16
17
18
19
20
# File 'lib/iex/resources/base.rb', line 12

def self.float_to_percentage(float_number)
  return unless float_number.is_a? Numeric
  return '+0.00%' if float_number.zero?
  [
    float_number > 0 ? '+' : '',
    format('%.2f', float_number * 100),
    '%'
  ].join
end

.symbol(symbol, &_block) ⇒ Object


4
5
6
7
8
9
10
# File 'lib/iex/resources/base.rb', line 4

def self.symbol(symbol, &_block)
  yield
rescue Faraday::ResourceNotFound => e
  raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
rescue Faraday::ClientError => e
  raise IEX::Errors::ClientError, e.response
end

.to_dollar(amount:, ignore_cents: true) ⇒ Object


22
23
24
# File 'lib/iex/resources/base.rb', line 22

def self.to_dollar(amount:, ignore_cents: true)
  MoneyHelper.money_to_text(amount, 'USD', nil, no_cents: ignore_cents)
end