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



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?



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

def description
  @schema.description
end

#exampleString?



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?



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

def format
  @schema.format
end

#optionsHash



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

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

#patternString?



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

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

#read_onlytrue?



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

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

#typeString?



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

def type
  if @schema.type
    @schema.type.join(", ")
  end
end