Class: Jdoc::Resource
- Inherits:
-
Object
- Object
- Jdoc::Resource
- Defined in:
- lib/jdoc/resource.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#anchor ⇒ String
Href anchor for putting link in ToC.
-
#description ⇒ String
Description for this schema, defined in description property.
-
#eql?(other) ⇒ Boolean
Defined to change uniqueness in Hash key.
-
#hash ⇒ Object
Defined to change uniqueness in Hash key.
-
#hyperlink ⇒ String
Markdown styled link text for this resource.
-
#initialize(schema) ⇒ Resource
constructor
A new instance of Resource.
- #links ⇒ Object
- #properties ⇒ Array<Jdoc::Property>
-
#title ⇒ String
Title defined in title property.
Constructor Details
#initialize(schema) ⇒ Resource
Returns a new instance of Resource.
6 7 8 |
# File 'lib/jdoc/resource.rb', line 6 def initialize(schema) @schema = schema end |
Instance Attribute Details
#schema ⇒ Object (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 |
#anchor ⇒ String
Returns Href anchor for putting link in ToC.
20 21 22 |
# File 'lib/jdoc/resource.rb', line 20 def anchor "#" + title.gsub(" ", "-").gsub(/[:\/]/, "").downcase end |
#description ⇒ String
Returns 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
51 52 53 |
# File 'lib/jdoc/resource.rb', line 51 def eql?(other) title == other.title end |
#hash ⇒ Object
Defined to change uniqueness in Hash key
46 47 48 |
# File 'lib/jdoc/resource.rb', line 46 def hash title.hash end |
#hyperlink ⇒ String
Returns Markdown styled link text for this resource.
27 28 29 |
# File 'lib/jdoc/resource.rb', line 27 def hyperlink "[#{title}](#{anchor})" end |
#links ⇒ Object
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 |
#properties ⇒ Array<Jdoc::Property>
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 |
#title ⇒ String
Returns 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 |