Sha256: 43aaf72abfd4f22204d9874f7ee933891923f7f108c1feb1a87ffe2b10437b07

Contents?: true

Size: 764 Bytes

Versions: 3

Compression:

Stored size: 764 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 }
        Float = Types::Strict::Float.optional.constructor { |value| value&.to_f }
        Integer = Types::Strict::Integer.optional.constructor { |value| value&.to_i }
        Boolean = Types::Bool.optional.constructor { |value| THE_TRUTH.fetch(value, false) }
        Date = Types::Date.optional.constructor do |value|
          next if value.nil? || value == ''

          begin
            ::Date.parse(value.to_s)
          rescue ::Date::Error
            raise Fortnox::API::AttributeError, 'invalid date'
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fortnox-api-0.8.2 lib/fortnox/api/types/nullable.rb
fortnox-api-0.8.1 lib/fortnox/api/types/nullable.rb
fortnox-api-0.9.0 lib/fortnox/api/types/nullable.rb