Sha256: aa4df8109b50f74213a181310e9dac712fde0449949ccc7a41c190a5c47c42da
Contents?: true
Size: 1.02 KB
Versions: 55
Compression:
Stored size: 1.02 KB
Contents
require 'json' require 'time' module CPEE class ValueHelper 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 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 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 end end
Version data entries
55 entries across 55 versions & 1 rubygems