class CckForms::ParameterTypeClass::Integer

Represents a decimal value.

Public Instance Methods

build_form(form_builder, options = {}) click to toggle source

Examples of options (works only if options == :select or options == :search):

ranges:   [['not more that 10', '/10'], ['11-20', '11/20'], ['21-30', '21/30'], ['more that 30', '31/']]
counting: [['one', '1'], ['two', '2'], ['three', '3']]
combined: [['one', '1'], ['two', '2'], ['three and more', '3/']]

Other options:

only    - leave only these keys (array/string)
# File lib/cck_forms/parameter_type_class/integer.rb, line 49
def build_form(form_builder, options = {})
  set_value_in_hash options

  default_style = {class: 'form-control input-small'}

  if options[:for] == :search
    res = []
    as = options[:as]
    only = options[:only]
    options = options.except :only, :for

    if as == :select
      res << form_builder.select(:value, [['', '']] + options[:values], options.merge(selected: options[:value]), class: 'form-control input-small')
    else
      value = options[:value].is_a?(Hash) ? options[:value].symbolize_keys : {}

      if !only || only == :low
        res << form_builder.text_field(:l, options.merge(index: 'value', value: value[:l]).reverse_merge(default_style))
      end

      if !only || only == :high
        res << form_builder.text_field(:h, options.merge(index: 'value', value: value[:h]).reverse_merge(default_style))
      end
    end

    res.join ' – '
  else
    form_builder.number_field :value, options.reverse_merge(default_style)
  end
end
mongoize() click to toggle source
# File lib/cck_forms/parameter_type_class/integer.rb, line 6
def mongoize
  value.to_i
end
to_s(_options = nil) click to toggle source
# File lib/cck_forms/parameter_type_class/integer.rb, line 10
def to_s(_options = nil)
  value.to_i != 0 ? value.to_i.to_s : ''
end