Class: Fluent::Json::Schema::Terms::Num

Inherits:
Field
  • Object
show all
Defined in:
lib/fluent/json/schema/terms/num.rb

Direct Known Subclasses

Int

Instance Attribute Summary collapse

Attributes inherited from Field

#constraints, #default, #enum, #name, #required, #version

Instance Method Summary collapse

Methods inherited from Field

#mandate, #optionalise

Constructor Details

#initialize(name, type = :number) ⇒ Num

Returns a new instance of Num.



8
9
10
11
# File 'lib/fluent/json/schema/terms/num.rb', line 8

def initialize(name, type=:number)
  super(name)
  @type = type
end

Instance Attribute Details

#exclusive_maximumObject (readonly)

Returns the value of attribute exclusive_maximum.



6
7
8
# File 'lib/fluent/json/schema/terms/num.rb', line 6

def exclusive_maximum
  @exclusive_maximum
end

#exclusive_minimumObject (readonly)

Returns the value of attribute exclusive_minimum.



6
7
8
# File 'lib/fluent/json/schema/terms/num.rb', line 6

def exclusive_minimum
  @exclusive_minimum
end

#maximumObject (readonly)

Returns the value of attribute maximum.



6
7
8
# File 'lib/fluent/json/schema/terms/num.rb', line 6

def maximum
  @maximum
end

#minimumObject (readonly)

Returns the value of attribute minimum.



6
7
8
# File 'lib/fluent/json/schema/terms/num.rb', line 6

def minimum
  @minimum
end

#multiple_ofObject (readonly)

Returns the value of attribute multiple_of.



6
7
8
# File 'lib/fluent/json/schema/terms/num.rb', line 6

def multiple_of
  @multiple_of
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/fluent/json/schema/terms/num.rb', line 6

def type
  @type
end

Instance Method Details

#as_jsonObject



27
28
29
30
31
32
33
34
# File 'lib/fluent/json/schema/terms/num.rb', line 27

def as_json
  super({ type: @type }).merge!(
    self.as_json_fragment(
      :minimum, :minimum, :maximum, :exclusive_minimum, 
      :exclusive_maximum, :multiple_of
    )
  )
end

#set(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fluent/json/schema/terms/num.rb', line 13

def set(options={})
  super(options)
  @minimum ||= options[:min]
  @maximum ||= options[:max]
  
  if not options[:exclusive].nil?
    @exclusive_minimum = options[:exclusive].include?(:min)
    @exclusive_maximum = options[:exclusive].include?(:max)
  end

  @multiple_of ||= options[:mult]
  return self
end