Class: Jdoc::Resource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • schema (JsonSchema::Schema)


6
7
8
# File 'lib/jdoc/resource.rb', line 6

def initialize(schema)
  @schema = schema
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



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

def schema
  @schema
end

Instance Method Details

#<=>(other) ⇒ Object



55
56
57
# File 'lib/jdoc/resource.rb', line 55

def <=>(other)
  title <=> other.title
end

#anchorString

Returns Href anchor for putting link in ToC.

Examples:

resource.anchor #=> "#app"

Returns:

  • (String)

    Href anchor for putting link in ToC



20
21
22
# File 'lib/jdoc/resource.rb', line 20

def anchor
  "#" + title.gsub(" ", "-").gsub(/[:\/]/, "").downcase
end

#descriptionString

Returns Description for this schema, defined in description property.

Examples:

resource.description #=> "An app is a program to be deployed."

Returns:

  • (String)

    Description for this schema, defined in description property



13
14
15
# File 'lib/jdoc/resource.rb', line 13

def description
  @schema.description
end

#eql?(other) ⇒ Boolean

Defined to change uniqueness in Hash key

Returns:

  • (Boolean)


51
52
53
# File 'lib/jdoc/resource.rb', line 51

def eql?(other)
  title == other.title
end

#hashObject

Defined to change uniqueness in Hash key



46
47
48
# File 'lib/jdoc/resource.rb', line 46

def hash
  title.hash
end

Returns Markdown styled link text for this resource.

Examples:

resource.hyperlink #=> "[App](#apps)"

Returns:

  • (String)

    Markdown styled link text for this resource



27
28
29
# File 'lib/jdoc/resource.rb', line 27

def hyperlink
  "[#{title}](#{anchor})"
end


59
60
61
62
63
64
65
# File 'lib/jdoc/resource.rb', line 59

def links
  @links ||= @schema.links.map do |link|
    if link.method && link.href
      Link.new(link)
    end
  end.compact
end

#propertiesArray<Jdoc::Property>

Returns:



39
40
41
42
43
# File 'lib/jdoc/resource.rb', line 39

def properties
  @schema.properties.map do |name, schema|
    Property.new(name: name, schema: schema)
  end
end

#titleString

Returns Title defined in title property.

Examples:

resource.title #=> "App"

Returns:

  • (String)

    Title defined in title property



34
35
36
# File 'lib/jdoc/resource.rb', line 34

def title
  @title ||= @schema.title || @schema.pointer.split("/").last.camelize
end