Class: Jdoc::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/jdoc/property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, schema: nil) ⇒ Property

Returns a new instance of Property.

Parameters:

  • name (String) (defaults to: nil)
  • schema (JsonSchema::Schema) (defaults to: nil)


7
8
9
10
# File 'lib/jdoc/property.rb', line 7

def initialize(name: nil, schema: nil)
  @name = name
  @schema = schema
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/jdoc/property.rb', line 3

def name
  @name
end

Instance Method Details

#descriptionString?

Returns Description text, defined in description property.

Returns:

  • (String, nil)

    Description text, defined in description property



24
25
26
# File 'lib/jdoc/property.rb', line 24

def description
  @schema.description
end

#exampleString?

Returns Example value, defined in example property.

Returns:

  • (String, nil)

    Example value, defined in example property



29
30
31
32
33
# File 'lib/jdoc/property.rb', line 29

def example
  if @schema.data.has_key?("example")
    %<`#{@schema.data["example"].inspect}`>
  end
end

#formatStirng?

Returns Format constraint, defined in format property.

Returns:

  • (Stirng, nil)

    Format constraint, defined in format property



43
44
45
# File 'lib/jdoc/property.rb', line 43

def format
  @schema.format
end

#optionsHash

Returns Key-Value pair of metadata of this property.

Returns:

  • (Hash)

    Key-Value pair of metadata of this property



13
14
15
16
17
18
19
20
21
# File 'lib/jdoc/property.rb', line 13

def options
  {
    Example: example,
    Type: type,
    Format: format,
    Pattern: pattern,
    ReadOnly: read_only,
  }.reject {|key, value| value.nil? }
end

#patternString?

Returns Pattern constraint, defined in pattern property.

Returns:

  • (String, nil)

    Pattern constraint, defined in pattern property



36
37
38
39
40
# File 'lib/jdoc/property.rb', line 36

def pattern
  if str = @schema.pattern
    "`#{str.inspect}`"
  end
end

#read_onlytrue?

Returns True if readOnly property is defined and it’s true.

Returns:

  • (true, nil)

    True if readOnly property is defined and it’s true



48
49
50
# File 'lib/jdoc/property.rb', line 48

def read_only
  true if @schema.read_only == true
end

#typeString?

Returns Possible types defined in type property.

Returns:

  • (String, nil)

    Possible types defined in type property



53
54
55
56
57
# File 'lib/jdoc/property.rb', line 53

def type
  unless @schema.type.empty?
    @schema.type.join(", ")
  end
end