Module: Lean::Attributes::CoercionHelpers
- Defined in:
- lib/lean-attributes/attributes/coercion_helpers.rb
Instance Method Summary collapse
- #coerce_to_array(value) ⇒ Object
- #coerce_to_bigdecimal(value) ⇒ Object
- #coerce_to_date(value) ⇒ Object
- #coerce_to_datetime(value) ⇒ Object
- #coerce_to_integer(value) ⇒ Object
- #coerce_to_string(value) ⇒ Object
- #coerce_to_symbol(value) ⇒ Object
- #coerce_to_time(value) ⇒ Object
Instance Method Details
#coerce_to_array(value) ⇒ Object
4 5 6 |
# File 'lib/lean-attributes/attributes/coercion_helpers.rb', line 4 def coerce_to_array(value) Array(value) unless value.nil? end |
#coerce_to_bigdecimal(value) ⇒ Object
8 9 10 |
# File 'lib/lean-attributes/attributes/coercion_helpers.rb', line 8 def coerce_to_bigdecimal(value) BigDecimal.new(value, 0) unless value.nil? end |
#coerce_to_date(value) ⇒ Object
12 13 14 |
# File 'lib/lean-attributes/attributes/coercion_helpers.rb', line 12 def coerce_to_date(value) Date.parse(value) unless value.nil? end |
#coerce_to_datetime(value) ⇒ Object
16 17 18 |
# File 'lib/lean-attributes/attributes/coercion_helpers.rb', line 16 def coerce_to_datetime(value) DateTime.parse(value) unless value.nil? end |
#coerce_to_integer(value) ⇒ Object
20 21 22 |
# File 'lib/lean-attributes/attributes/coercion_helpers.rb', line 20 def coerce_to_integer(value) value.to_i unless value.nil? end |
#coerce_to_string(value) ⇒ Object
24 25 26 |
# File 'lib/lean-attributes/attributes/coercion_helpers.rb', line 24 def coerce_to_string(value) value.to_s unless value.nil? end |
#coerce_to_symbol(value) ⇒ Object
28 29 30 |
# File 'lib/lean-attributes/attributes/coercion_helpers.rb', line 28 def coerce_to_symbol(value) value.to_sym unless value.nil? end |
#coerce_to_time(value) ⇒ Object
32 33 34 |
# File 'lib/lean-attributes/attributes/coercion_helpers.rb', line 32 def coerce_to_time(value) Time.new(value) unless value.nil? end |