Sha256: 91beec6f0308c973cbe5d3204226f44999a10ae35c8c3160e2ebd1458a918a57

Contents?: true

Size: 929 Bytes

Versions: 6

Compression:

Stored size: 929 Bytes

Contents

require 'date'

module Fortnox
  module API
    module Types

      module Nullable
        String = Types::Strict::String.optional.constructor{ |value| value.to_s unless value.nil? }
        Float = Types::Strict::Float.optional.constructor{ |value| value.to_f unless value.nil? }
        Integer = Types::Strict::Int.optional.constructor{ |value| value.to_i unless value.nil? }
        Boolean = Types::Bool.optional.constructor{ |value| THE_TRUTH.fetch( value ){ false } }
        # TODO: Improve parsing!
        # In case date parsing fails, ArgumentError is thrown. Currently, it is rescued in Repository::Loaders.find.
        # That method assumes that the exception is due to invalid argument to the find method, which is not the case
        # if it is raised from here!
        Date = Types::Date.optional.constructor{ |value| ::Date.parse( value.to_s ) unless value.nil? || value == '' }
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fortnox-api-0.5.2 lib/fortnox/api/types/nullable.rb
fortnox-api-0.5.1 lib/fortnox/api/types/nullable.rb
fortnox-api-0.5.0 lib/fortnox/api/types/nullable.rb
fortnox-api-0.4.0 lib/fortnox/api/types/nullable.rb
fortnox-api-0.3.0 lib/fortnox/api/types/nullable.rb
fortnox-api-0.2.0 lib/fortnox/api/types/nullable.rb