Class: Amount::Parser
- Inherits:
-
Object
- Object
- Amount::Parser
- Defined in:
- lib/amount/parser.rb
Overview
Parses compact amount strings such as ‘USDC|1.50`.
Constant Summary collapse
- VERSION_PREFIX =
/\A(v\d+):(.*)\z/- SUPPORTED_VERSION =
"v1"
Instance Method Summary collapse
-
#initialize(input) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(input) ⇒ Parser
Returns a new instance of Parser.
9 10 11 |
# File 'lib/amount/parser.rb', line 9 def initialize(input) @input = input end |
Instance Method Details
#parse ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/amount/parser.rb', line 13 def parse symbol, value = parse_components validate!(symbol, value) Amount.new(value, symbol) rescue ArgumentError raise InvalidInput, "cannot parse #{@input.inspect}" end |