Class: CPEE::ValueHelper
- Inherits:
-
Object
- Object
- CPEE::ValueHelper
- Defined in:
- lib/cpee/value_helper.rb
Class Method Summary collapse
Class Method Details
.generate(value) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/cpee/value_helper.rb', line 21 def self::generate(value) if [String, Integer, Float, TrueClass, FalseClass, Date].include? value.class value.to_s elsif [Hash, Array].include? value.class JSON::generate(value) elsif value.respond_to?(:to_s) value.to_s end end |
.parse(value) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cpee/value_helper.rb', line 31 def self::parse(value) case value.downcase when 'true' true when 'false' false when 'nil', 'null' nil else begin JSON::parse(value) rescue (Integer value rescue nil) || (Float value rescue nil) || value.to_s rescue nil || '' end end end |
.parse_extended(value) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cpee/value_helper.rb', line 48 def self::parse_extended(value) if [String].include? value.class self::parse(value) elsif [Array, NilClass, Integer, Float, TrueClass, FalseClass, Date].include? value.class value elsif value.respond_to?(:to_s) value.to_s else '' end end |