Sha256: 9a0abcfe040fb2b144f07914be5a52264ec13042c3668b2c0fb8a8c9ffa95c50

Contents?: true

Size: 960 Bytes

Versions: 8

Compression:

Stored size: 960 Bytes

Contents

# frozen_string_literal: true

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

8 entries across 8 versions & 1 rubygems

Version Path
fortnox-api-0.8.0 lib/fortnox/api/types/nullable.rb
fortnox-api-0.7.2 lib/fortnox/api/types/nullable.rb
fortnox-api-0.7.1 lib/fortnox/api/types/nullable.rb
fortnox-api-0.7.0 lib/fortnox/api/types/nullable.rb
fortnox-api-0.6.3 lib/fortnox/api/types/nullable.rb
fortnox-api-0.6.2 lib/fortnox/api/types/nullable.rb
fortnox-api-0.6.1 lib/fortnox/api/types/nullable.rb
fortnox-api-0.6.0 lib/fortnox/api/types/nullable.rb