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



322
323
324
# File 'lib/formeze.rb', line 322

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

.scrub(input, method_names) ⇒ Object



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

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



326
327
328
329
330
331
332
333
334
# File 'lib/formeze.rb', line 326

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



346
347
348
349
350
# File 'lib/formeze.rb', line 346

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

  form.extend ClassMethods
end

.translate(key, options) ⇒ Object



342
343
344
# File 'lib/formeze.rb', line 342

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