Class: Apiwork::Introspection::Param::Number

Inherits:
Base
  • Object
show all
Defined in:
lib/apiwork/introspection/param/number.rb

Overview

Number param representing floating-point number values.

Examples:

Basic usage

param.type # => :number
param.scalar? # => true
param.number? # => true
param.numeric? # => true

Constraints

param.min # => 0.0 or nil
param.max # => 100.0 or nil
param.boundable? # => true
param.formattable? # => false

Enum

if param.enum?
  param.enum # => [0.5, 1.0, 1.5]
  param.enum_reference? # => false
end

Instance Method Summary collapse

Methods inherited from Base

#array?, #binary?, #boolean?, #date?, #datetime?, #decimal?, #default?, #deprecated?, #description, #initialize, #integer?, #literal?, #nullable?, #object?, #optional?, #partial?, #record?, #reference?, #string?, #tag, #time?, #type, #union?, #unknown?, #uuid?

Constructor Details

This class inherits a constructor from Apiwork::Introspection::Param::Base

Instance Method Details

#boundable?Boolean

Whether this param is boundable.

Returns:



114
115
116
# File 'lib/apiwork/introspection/param/number.rb', line 114

def boundable?
  true
end

#concrete?Boolean

Whether this param is concrete.

Returns:



66
67
68
# File 'lib/apiwork/introspection/param/number.rb', line 66

def concrete?
  true
end

#defaultObject?

The default for this param.

Returns ‘nil` for both “no default” and “default is explicitly `nil`”. Use Base#default? to distinguish these cases.

Returns:



34
35
36
# File 'lib/apiwork/introspection/param/number.rb', line 34

def default
  @dump[:default]
end

#enumArray<Numeric>, ...

The enum for this param.

Returns:

  • (Array<Numeric>, Symbol, nil)


90
91
92
# File 'lib/apiwork/introspection/param/number.rb', line 90

def enum
  @dump[:enum]
end

#enum?Boolean

Whether this param has an enum.

Returns:



82
83
84
# File 'lib/apiwork/introspection/param/number.rb', line 82

def enum?
  @dump[:enum].present?
end

#enum_reference?Boolean

Whether this param is an enum reference.

Returns:



98
99
100
# File 'lib/apiwork/introspection/param/number.rb', line 98

def enum_reference?
  @dump[:enum].is_a?(Symbol)
end

#exampleObject?

The example for this param.

Returns:



42
43
44
# File 'lib/apiwork/introspection/param/number.rb', line 42

def example
  @dump[:example]
end

#formattable?Boolean

Whether this param is formattable.

Returns:



130
131
132
# File 'lib/apiwork/introspection/param/number.rb', line 130

def formattable?
  false
end

#maxNumeric?

The maximum for this param.

Returns:

  • (Numeric, nil)


58
59
60
# File 'lib/apiwork/introspection/param/number.rb', line 58

def max
  @dump[:max]
end

#minNumeric?

The minimum for this param.

Returns:

  • (Numeric, nil)


50
51
52
# File 'lib/apiwork/introspection/param/number.rb', line 50

def min
  @dump[:min]
end

#number?Boolean

Whether this param is a number.

Returns:



122
123
124
# File 'lib/apiwork/introspection/param/number.rb', line 122

def number?
  true
end

#numeric?Boolean

Whether this param is numeric.

Returns:



106
107
108
# File 'lib/apiwork/introspection/param/number.rb', line 106

def numeric?
  true
end

#scalar?Boolean

Whether this param is scalar.

Returns:



74
75
76
# File 'lib/apiwork/introspection/param/number.rb', line 74

def scalar?
  true
end

#to_hHash

Converts this param to a hash.

Returns:

  • (Hash)


138
139
140
141
142
143
144
145
146
# File 'lib/apiwork/introspection/param/number.rb', line 138

def to_h
  result = super
  result[:default] = default
  result[:enum] = enum if enum?
  result[:example] = example
  result[:max] = max
  result[:min] = min
  result
end