Sha256: 8011bd0cd0f4c721d3dff65b6d9337ab43dc43b90f9d78a18db740a0512dd3bd

Contents?: true

Size: 706 Bytes

Versions: 2

Compression:

Stored size: 706 Bytes

Contents

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


class Fluent::Json::Schema::Terms::Str < Fluent::Json::Schema::Terms::Field
  attr_reader :format, :pattern, :min_length, :max_length

  def initialize(name, options={})
    super(name, options)
  end

  def set(options={})
    super(options)
    @min_length ||= options[:min]
    @max_length ||= options[:max]
    @format ||= options[:fmt]
    @pattern ||= options[:pattern]
    return self
  end

  def datetime
    @format = :'date-time'
  end

  def email
    @format = :email
  end

  def uri
    @format = :uri
  end

  def as_json
    super({ type: :string }).merge!(
      self.as_json_fragment(:min_length, :max_length, :format, :pattern)
    )
  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/str.rb
fluent-json-schema-0.1.1 lib/fluent/json/schema/terms/str.rb