Class: Monetize::Collection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/monetize/collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  if input.respond_to? :strip
    @input = input.clone.strip
  else
    fail ArgumentError, 'Input must be a string'
  end

  @currency = currency
  @options = options
  @list = []
end

Instance Attribute Details

#currencyObject (readonly)

Returns the value of attribute currency.



11
12
13
# File 'lib/monetize/collection.rb', line 11

def currency
  @currency
end

#inputObject (readonly)

Returns the value of attribute input.



11
12
13
# File 'lib/monetize/collection.rb', line 11

def input
  @input
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/monetize/collection.rb', line 11

def options
  @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, options = {})
  new(input, currency, options).parse
end

Instance Method Details

#parseObject



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, options) }
  else
    @list = split_list.map { |fragment| Monetize.parse(fragment, currency, options) }
  end

  self
end

#range?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/monetize/collection.rb', line 39

def range?
  RANGE_SPLIT =~ input
end