Sha256: 649398090c70c2ed7fbbf947ea50ad8f32ea28285507838b75a8cb60e3a03f0b

Contents?: true

Size: 849 Bytes

Versions: 18

Compression:

Stored size: 849 Bytes

Contents

module Frodo
  module Properties
    # Defines the Time Frodo type.
    class Time < Frodo::Property
      # Returns the property value, properly typecast
      # @return [Time,nil]
      def value
        if (@value.nil? || @value.empty?) && allows_nil?
          nil
        else
          ::Time.strptime(@value, '%H:%M:%S%:z')
        end
      end

      # Sets the property value
      # @params new_value [Time]
      def value=(new_value)
        validate(new_value)
        @value = parse_value(new_value)
      end

      # The Frodo type name
      def type
        'Edm.Time'
      end

      private

      def validate(value)
        unless value.is_a?(::Time)
          validation_error 'Value is not a time object'
        end
      end

      def parse_value(value)
        value.strftime('%H:%M:%S%:z')
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
frodo-0.12.8 lib/frodo/properties/time.rb
frodo-0.12.7 lib/frodo/properties/time.rb
frodo-0.12.6 lib/frodo/properties/time.rb
frodo-0.12.5 lib/frodo/properties/time.rb
frodo-0.12.4 lib/frodo/properties/time.rb
frodo-0.12.2 lib/frodo/properties/time.rb
frodo-0.12.1 lib/frodo/properties/time.rb
frodo-0.12.0 lib/frodo/properties/time.rb
frodo-0.11.0 lib/frodo/properties/time.rb
frodo-0.10.8 lib/frodo/properties/time.rb
frodo-0.10.7 lib/frodo/properties/time.rb
frodo-0.10.6 lib/frodo/properties/time.rb
frodo-0.10.5 lib/frodo/properties/time.rb
frodo-0.10.4 lib/frodo/properties/time.rb
frodo-0.10.3 lib/frodo/properties/time.rb
frodo-0.10.2 lib/frodo/properties/time.rb
frodo-0.10.1 lib/frodo/properties/time.rb
frodo-0.10.0 lib/frodo/properties/time.rb