Sha256: 29a39fbb585590f9fe172fd782af2dfa761bf05188ffe9a645e50a7b4245502c

Contents?: true

Size: 829 Bytes

Versions: 2

Compression:

Stored size: 829 Bytes

Contents

require 'fluent/json/schema/terms/field'


class Fluent::Json::Schema::Terms::Num < Fluent::Json::Schema::Terms::Field

  attr_reader :type, :minimum, :maximum, :exclusive_minimum, :exclusive_maximum, :multiple_of

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

  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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fluent-json-schema-0.1.2 lib/fluent/json/schema/terms/num.rb
fluent-json-schema-0.1.1 lib/fluent/json/schema/terms/num.rb