Module: Formeze
- Defined in:
- lib/formeze.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Classes: Field, Form, KeyError, RequestCGI, Validation, ValidationError, ValueError
Class Method Summary
collapse
Class Method Details
.label(field_name) ⇒ Object
334
335
336
|
# File 'lib/formeze.rb', line 334
def self.label(field_name)
field_name.to_s.tr('_', ' ').capitalize
end
|
.scrub(input, method_names) ⇒ Object
348
349
350
351
352
|
# File 'lib/formeze.rb', line 348
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_methods ⇒ Object
338
339
340
341
342
343
344
345
346
|
# File 'lib/formeze.rb', line 338
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
358
359
360
361
362
|
# File 'lib/formeze.rb', line 358
def self.setup(form)
form.send :include, InstanceMethods
form.extend ClassMethods
end
|
.translate(key, options) ⇒ Object
354
355
356
|
# File 'lib/formeze.rb', line 354
def self.translate(key, options)
defined?(I18n) ? I18n.translate(key, options) : options.fetch(:default)
end
|