Class: Jdoc::Schema
- Inherits:
-
Object
- Object
- Jdoc::Schema
- Defined in:
- lib/jdoc/schema.rb
Class Method Summary collapse
-
.extract_links(json_schema) ⇒ Array
Recursively extracts all links in given JSON schema.
Instance Method Summary collapse
-
#initialize(schema) ⇒ Schema
constructor
A new instance of Schema.
-
#links_indexed_by_resource ⇒ Hash{Jdoc::Schema => Array}
Linkes table indexed by their schemata.
-
#title ⇒ String?
Title property of this schema.
Constructor Details
#initialize(schema) ⇒ Schema
Returns a new instance of Schema.
12 13 14 |
# File 'lib/jdoc/schema.rb', line 12 def initialize(schema) @json_schema = JsonSchema.parse!(schema).tap(&:expand_references!) end |
Class Method Details
.extract_links(json_schema) ⇒ Array
Recursively extracts all links in given JSON schema
6 7 8 9 |
# File 'lib/jdoc/schema.rb', line 6 def self.extract_links(json_schema) links = json_schema.links.select {|link| link.method && link.href } links + json_schema.properties.map {|key, schema| extract_links(schema) }.flatten end |
Instance Method Details
#links_indexed_by_resource ⇒ Hash{Jdoc::Schema => Array}
Returns Linkes table indexed by their schemata.
17 18 19 20 21 22 |
# File 'lib/jdoc/schema.rb', line 17 def links_indexed_by_resource @links_indexed_by_schema ||= links.inject(Hash.new {|h, k| h[k] = [] }) do |result, link| result[link.resource] << link result end end |
#title ⇒ String?
Returns Title property of this schema.
27 28 29 |
# File 'lib/jdoc/schema.rb', line 27 def title @json_schema.title end |