Class: Locomotive::Steam::Liquid::Filters::Number::NumberProxyHelper

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::NumberHelper
Defined in:
lib/locomotive/steam/liquid/filters/number.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, context) ⇒ NumberProxyHelper

Returns a new instance of NumberProxyHelper.



27
28
29
30
# File 'lib/locomotive/steam/liquid/filters/number.rb', line 27

def initialize(name, context)
  @name     = name
  @context  = context
end

Instance Method Details

#invoke(input, options) ⇒ Object



32
33
34
35
# File 'lib/locomotive/steam/liquid/filters/number.rb', line 32

def invoke(input, options)
  _options = parse_and_interpolate_options(options)
  send :"number_to_#{@name}", input, _options
end

#parse_and_interpolate_options(string_or_array) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/locomotive/steam/liquid/filters/number.rb', line 37

def parse_and_interpolate_options(string_or_array)
  return {} if string_or_array.empty?

  string = [*string_or_array].flatten.join(', ')
  arguments = Solid::Arguments.parse(string)

  (arguments.interpolate(@context).first || {})
end