Module: I18nYamlEditor::Cast
- Included in:
- Update
- Defined in:
- lib/i18n_yaml_editor/cast.rb
Overview
Transformation provides
Constant Summary collapse
- TYPES =
Lists all supported types of conversions
%i[numeric boolean array].freeze
- CHECK =
Contains a check method for each supported type
{ numeric: ->(klass) { klass < Numeric }, boolean: ->(klass) { [TrueClass, FalseClass].include?(klass) }, array: ->(klass) { klass == Array } }.freeze
- CONVERT =
Contains a conversion method for each supported type
{ numeric: lambda do |value| num = BigDecimal(value) num.frac.zero? ? num.to_i : num.to_f end, boolean: ->(value) { value.casecmp('true').zero? }, array: ->(value) { value.split("\r\n") } }.freeze
Instance Method Summary collapse
-
#cast(klass, value) ⇒ Object
Converts a given value to a specific data type.