Module: DPay::Internal::Coerce
- Defined in:
- lib/dpay/internal/coerce.rb,
sig/dpay/internal/coerce.rbs
Class Method Summary collapse
- .boolean(value) ⇒ Object
- .integer(value) ⇒ Object
- .list(value) ⇒ Object
- .money(value, currency = Currency::PLN) ⇒ Object
- .optional_integer(value) ⇒ Object
- .string(value) ⇒ Object
Instance Method Summary collapse
- #self?.boolean ⇒ Boolean
- #self?.integer ⇒ Integer
- #self?.list ⇒ Array[Hash[String, untyped]]
- #self?.money ⇒ Money
- #self?.optional_integer ⇒ Integer?
- #self?.string ⇒ String?
Class Method Details
.boolean(value) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dpay/internal/coerce.rb', line 19 def boolean(value) return value if value.is_a?(TrueClass) || value.is_a?(FalseClass) return value != 0 if value.is_a?(Numeric) return !value.empty? && value != "0" if value.is_a?(String) false end |
.integer(value) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/dpay/internal/coerce.rb', line 27 def integer(value) return value.to_i if value.is_a?(Numeric) return value.to_i if value.is_a?(String) && /\A\s*[+-]?\d+/.match?(value) 0 end |
.list(value) ⇒ Object
41 42 43 |
# File 'lib/dpay/internal/coerce.rb', line 41 def list(value) value.is_a?(Array) ? value.grep(Hash) : [] end |
.money(value, currency = Currency::PLN) ⇒ Object
15 16 17 |
# File 'lib/dpay/internal/coerce.rb', line 15 def money(value, currency = Currency::PLN) Money.try_from_api_number(value.nil? ? 0 : value, currency) || Money.pln(0) end |
.optional_integer(value) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/dpay/internal/coerce.rb', line 34 def optional_integer(value) return value.to_i if value.is_a?(Numeric) return value.to_i if value.is_a?(String) && /\A\s*[+-]?\d+\z/.match?(value) nil end |
Instance Method Details
#self?.boolean ⇒ Boolean
6 |
# File 'sig/dpay/internal/coerce.rbs', line 6
def self?.boolean: (untyped value) -> bool
|
#self?.integer ⇒ Integer
7 |
# File 'sig/dpay/internal/coerce.rbs', line 7
def self?.integer: (Integer | Float | String | bool | nil value) -> Integer
|
#self?.list ⇒ Array[Hash[String, untyped]]
9 |
# File 'sig/dpay/internal/coerce.rbs', line 9
def self?.list: (untyped value) -> Array[Hash[String, untyped]]
|
#self?.money ⇒ Money
5 |
# File 'sig/dpay/internal/coerce.rbs', line 5
def self?.money: (untyped value, ?String currency) -> Money
|
#self?.optional_integer ⇒ Integer?
8 |
# File 'sig/dpay/internal/coerce.rbs', line 8
def self?.optional_integer: (Integer | Float | String | bool | nil value) -> Integer?
|
#self?.string ⇒ String?
4 |
# File 'sig/dpay/internal/coerce.rbs', line 4
def self?.string: (untyped value) -> String?
|