class Gum::Factory

Public Class Methods

args_to_mapping(args) click to toggle source
# File lib/gum/factory.rb, line 11
def self.args_to_mapping(args)
  args.inject({}) do |mapping, arg|
    mapping.update normalize_mapping(arg)
  end
end
build(type, args) { |new(type, param, field, options)| ... } click to toggle source
# File lib/gum/factory.rb, line 3
def self.build(type, args)
  mapping = args_to_mapping(args)
  options = mapping.delete(:options)
  mapping.each do |param, field|
    yield new(type, param, field, options)
  end
end
new(type, param, field, options) click to toggle source
# File lib/gum/factory.rb, line 28
def self.new(type, param, field, options)
  filter = type.is_a?(Class) ? type : Filters.const_get(type.to_s.camelize, false)
  filter.new param, field, options
end
normalize_mapping(mapping) click to toggle source
# File lib/gum/factory.rb, line 17
def self.normalize_mapping(mapping)
  case mapping
    when Hash
      mapping
    when Array
      mapping.zip(mapping).to_h
    else
      { mapping => mapping }
  end
end