Module: Tunable::Normalizer
- Included in:
- Tunable
- Defined in:
- lib/tunable/normalizer.rb
Constant Summary collapse
- TRUTHIES =
['true', 't', 'on', 'yes', 'y'].freeze
- FALSIES =
['false', 'f', 'off', 'no', 'n'].freeze
Instance Method Summary collapse
- #matching_type(a, b) ⇒ Object
-
#normalize_and_get(val) ⇒ Object
Called from Setting#normalized_value and DeviceActions#toggle_action.
- #normalize_value(val, type = nil) ⇒ Object
Instance Method Details
#matching_type(a, b) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/tunable/normalizer.rb', line 26 def matching_type(a, b) if [true, false].include?(a) return [true, false].include?(b) else a.class == b.class end end |
#normalize_and_get(val) ⇒ Object
Called from Setting#normalized_value and DeviceActions#toggle_action
22 23 24 |
# File 'lib/tunable/normalizer.rb', line 22 def normalize_and_get(val) normalize_value(val) end |
#normalize_value(val, type = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tunable/normalizer.rb', line 8 def normalize_value(val, type = nil) if type && [TrueClass, FalseClass].include?(type) return false if val.to_s == '0' return true if val.to_s == '1' end return true if TRUTHIES.include?(val.to_s) return false if FALSIES.include?(val.to_s) return Integer(val) if is_integer?(val) return if val.blank? # false.blank? returns true so this needs to go after the 0 line val end |