Class: IEX::Resources::Resource
- Inherits:
-
Hashie::Trash
- Object
- Hashie::Trash
- IEX::Resources::Resource
- Includes:
- Hashie::Extensions::IgnoreUndeclared
- Defined in:
- lib/iex/resources/resource.rb
Direct Known Subclasses
AdvancedStats, BalanceSheet, CashFlow, Chart::Base, Company, Crypto, CurrencyRate, Dividends, Earnings, HistorialPrices, Income, KeyStats, LargestTrades, Logo, News, OHLC, OHLC::TimedPrice, Quote, Sectors, Symbol, Symbols
Class Method Summary collapse
- .float_to_percentage(float_number) ⇒ Object
-
.percentage_to_string(float_percent) ⇒ Object
Useful for values that are already a percent but we want to convert into a 2 decimal place string.
- .to_dollar(amount:, ignore_cents: true) ⇒ Object
Class Method Details
.float_to_percentage(float_number) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/iex/resources/resource.rb', line 6 def self.float_to_percentage(float_number) return unless float_number.is_a? Numeric return '+0.00%' if float_number.zero? [ float_number.positive? ? '+' : '', format('%.2f', float_number * 100), '%' ].join end |
.percentage_to_string(float_percent) ⇒ Object
Useful for values that are already a percent but we want to convert into a 2 decimal place string
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/iex/resources/resource.rb', line 18 def self.percentage_to_string(float_percent) return unless float_percent.is_a? Numeric return '+0.00%' if float_percent.zero? [ float_percent.positive? ? '+' : '', format('%.2f', float_percent), '%' ].join end |
.to_dollar(amount:, ignore_cents: true) ⇒ Object
29 30 31 |
# File 'lib/iex/resources/resource.rb', line 29 def self.to_dollar(amount:, ignore_cents: true) MoneyHelper.money_to_text(amount, 'USD', nil, no_cents: ignore_cents) end |