Class: Decidim::Attributes::IntegerWithUnits

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
decidim-core/lib/decidim/attributes/integer_with_units.rb

Overview

Custom attributes value to represent an Integer with units.

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'decidim-core/lib/decidim/attributes/integer_with_units.rb', line 11

def cast(value)
  return nil if value.nil?

  case value
  when ::Hash
    [value["0"].to_i.abs, value["1"].to_s]
  when ::Array
    return value if value.size != 2

    [value[0].to_i.abs, value[1].to_s]
  else
    value
  end
end

#typeObject



7
8
9
# File 'decidim-core/lib/decidim/attributes/integer_with_units.rb', line 7

def type
  :"decidim/attributes/integer_with_units"
end