Sha256: 82dcfea8dfd8c082ad780e57059ed3ee3b5dee6268bc34a8eefdc1a3193a7c5b

Contents?: true

Size: 705 Bytes

Versions: 2

Compression:

Stored size: 705 Bytes

Contents

module PropertySets
  module Casting

    def self.read(type, value)
      return nil if value.nil?

      case type
        when :string
          value
        when :datetime
          Time.parse(value).in_time_zone
        when :float
          value.to_f
        when :integer
          value.to_i
        when :boolean
          ![ "false", "0", "", "off", "n" ].member?(value.to_s.downcase)
      end
    end

    def self.write(type, value)
      return nil if value.nil?

      case type
        when :datetime
          if value.is_a?(String)
            value
          else
            value.in_time_zone("UTC").to_s
          end
        else
          value.to_s
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
property_sets-0.6.2 lib/property_sets/casting.rb
property_sets-0.5.8 lib/property_sets/casting.rb