Class: Monetize::Collection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/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.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/collection.rb', line 18

def initialize(input, currency = Money.default_currency, options = {})
  if input.respond_to? :strip
    @input = input.clone.strip
  else
    raise ArgumentError 'Input must be a string'
  end

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

Instance Attribute Details

#currencyObject (readonly)

Returns the value of attribute currency.



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

def currency
  @currency
end

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

.parse(input, currency = Money.default_currency, options = {}) ⇒ Object



14
15
16
# File 'lib/collection.rb', line 14

def self.parse(input, currency = Money.default_currency, options = {})
  new(input, currency, options).parse
end

Instance Method Details

#parseObject



30
31
32
33
34
35
36
37
38
# File 'lib/collection.rb', line 30

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)


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

def range?
  RANGE_SPLIT =~ input
end