Sha256: 3b019b9132adf81bf6b68f0e882a41816ce884e161edf8e5a35082c77f0c53ef

Contents?: true

Size: 448 Bytes

Versions: 14

Compression:

Stored size: 448 Bytes

Contents

module HaveAPI::Client
  class Parameters::Resource
    attr_reader :errors

    def initialize(params, desc, value)
      @errors = []
      @value = coerce(value)
    end

    def valid?
      @errors.empty?
    end

    def to_api
      @value
    end

    protected

    def coerce(v)
      if !v.is_a?(::Integer) && /\A\d+\z/ !~ v
        @errors << 'not a valid resource id'
        nil

      else
        v.to_i
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
haveapi-client-0.25.0 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.24.0 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.23.7 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.23.6 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.23.5 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.23.4 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.23.3 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.23.2 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.23.1 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.23.0 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.22.1 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.22.0 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.21.1 lib/haveapi/client/parameters/resource.rb
haveapi-client-0.21.0 lib/haveapi/client/parameters/resource.rb