Class: Monetize::Collection
- Inherits:
-
Object
- Object
- Monetize::Collection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/monetize/collection.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input, currency = Money.default_currency, options = {}) ⇒ Collection
constructor
A new instance of Collection.
- #parse ⇒ Object
- #range? ⇒ Boolean
Constructor Details
#initialize(input, currency = Money.default_currency, options = {}) ⇒ Collection
Returns a new instance of Collection.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/monetize/collection.rb', line 17 def initialize(input, currency = Money.default_currency, = {}) if input.respond_to? :strip @input = input.clone.strip else fail ArgumentError, 'Input must be a string' end @currency = currency @options = @list = [] end |
Instance Attribute Details
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
11 12 13 |
# File 'lib/monetize/collection.rb', line 11 def currency @currency end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
11 12 13 |
# File 'lib/monetize/collection.rb', line 11 def input @input end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/monetize/collection.rb', line 11 def @options end |
Class Method Details
.parse(input, currency = Money.default_currency, options = {}) ⇒ Object
13 14 15 |
# File 'lib/monetize/collection.rb', line 13 def self.parse(input, currency = Money.default_currency, = {}) new(input, currency, ).parse end |
Instance Method Details
#parse ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/monetize/collection.rb', line 29 def parse if range? @list = split_range.map { |fragment| Monetize.parse(fragment, currency, ) } else @list = split_list.map { |fragment| Monetize.parse(fragment, currency, ) } end self end |
#range? ⇒ Boolean
39 40 41 |
# File 'lib/monetize/collection.rb', line 39 def range? RANGE_SPLIT =~ input end |