Module: Formeze

Defined in:
lib/formeze.rb

Defined Under Namespace

Modules: ArrayAttrAccessor, ClassMethods, InstanceMethods Classes: Field, FieldSet, Form, KeyError, Validation, ValidationError, ValueError

Class Method Summary collapse

Class Method Details

.label(field_name) ⇒ Object



336
337
338
# File 'lib/formeze.rb', line 336

def self.label(field_name)
  field_name.to_s.tr('_', ' ').capitalize
end

.scrub(input, method_names) ⇒ Object



350
351
352
353
354
# File 'lib/formeze.rb', line 350

def self.scrub(input, method_names)
  Array(method_names).inject(input) do |tmp, method_name|
    scrub_methods.fetch(method_name).call(tmp)
  end
end

.scrub_methodsObject



340
341
342
343
344
345
346
347
348
# File 'lib/formeze.rb', line 340

def self.scrub_methods
  @scrub_methods ||= {
    :strip => :strip.to_proc,
    :upcase => :upcase.to_proc,
    :downcase => :downcase.to_proc,
    :squeeze => proc { |string| string.squeeze(' ') },
    :squeeze_lines => proc { |string| string.gsub(/(\r?\n)(\r?\n)(\r?\n)+/, '\\1\\2') }
  }
end

.setup(form) ⇒ Object



360
361
362
363
364
# File 'lib/formeze.rb', line 360

def self.setup(form)
  form.send :include, InstanceMethods

  form.extend ClassMethods
end

.translate(key, options) ⇒ Object



356
357
358
# File 'lib/formeze.rb', line 356

def self.translate(key, options)
  defined?(I18n) ? I18n.translate(key, options) : options.fetch(:default)
end