Module: Formeze

Defined in:
lib/formeze.rb

Defined Under Namespace

Modules: Block, ClassMethods, Errors, FormData, InstanceMethods, Labels, Presence Classes: Field, Form, KeyError, Validation, ValidationError, ValueError

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.excludeObject

Returns the value of attribute exclude.



142
143
144
# File 'lib/formeze.rb', line 142

def exclude
  @exclude
end

Class Method Details

.label(field_name) ⇒ Object



151
152
153
# File 'lib/formeze.rb', line 151

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

.scrub(input, method_names) ⇒ Object



165
166
167
168
169
# File 'lib/formeze.rb', line 165

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



155
156
157
158
159
160
161
162
163
# File 'lib/formeze.rb', line 155

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



171
172
173
174
175
# File 'lib/formeze.rb', line 171

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

  form.extend ClassMethods
end