Class: Chronicle::Schema::SchemaType
- Inherits:
-
Object
- Object
- Chronicle::Schema::SchemaType
- Defined in:
- lib/chronicle/schema/schema_type.rb
Overview
Represents a type in the RDF graph
TODO: rename ‘class` to `type` to match new class name
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#see_also ⇒ Object
Returns the value of attribute see_also.
-
#subtype_ids ⇒ Object
Returns the value of attribute subtype_ids.
-
#subtypes ⇒ Object
Returns the value of attribute subtypes.
-
#supertypes ⇒ Object
Returns the value of attribute supertypes.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_property(property) ⇒ Object
- #add_subtype_id(subtype_id) ⇒ Object
- #all_properties ⇒ Object
- #ancestors ⇒ Object
- #descendants ⇒ Object
-
#identifier ⇒ Object
FIXME.
-
#initialize(id) {|_self| ... } ⇒ SchemaType
constructor
A new instance of SchemaType.
- #inspect ⇒ Object
- #pretty_print(pp) ⇒ Object
- #short_id ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(id) {|_self| ... } ⇒ SchemaType
Returns a new instance of SchemaType.
16 17 18 19 20 21 22 |
# File 'lib/chronicle/schema/schema_type.rb', line 16 def initialize(id) @id = id @subtype_ids = [] @properties = [] yield self if block_given? end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
8 9 10 |
# File 'lib/chronicle/schema/schema_type.rb', line 8 def comment @comment end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/chronicle/schema/schema_type.rb', line 7 def id @id end |
#namespace ⇒ Object
Returns the value of attribute namespace.
8 9 10 |
# File 'lib/chronicle/schema/schema_type.rb', line 8 def namespace @namespace end |
#properties ⇒ Object
Returns the value of attribute properties.
8 9 10 |
# File 'lib/chronicle/schema/schema_type.rb', line 8 def properties @properties end |
#see_also ⇒ Object
Returns the value of attribute see_also.
8 9 10 |
# File 'lib/chronicle/schema/schema_type.rb', line 8 def see_also @see_also end |
#subtype_ids ⇒ Object
Returns the value of attribute subtype_ids.
8 9 10 |
# File 'lib/chronicle/schema/schema_type.rb', line 8 def subtype_ids @subtype_ids end |
#subtypes ⇒ Object
Returns the value of attribute subtypes.
8 9 10 |
# File 'lib/chronicle/schema/schema_type.rb', line 8 def subtypes @subtypes end |
#supertypes ⇒ Object
Returns the value of attribute supertypes.
8 9 10 |
# File 'lib/chronicle/schema/schema_type.rb', line 8 def supertypes @supertypes end |
Instance Method Details
#==(other) ⇒ Object
59 60 61 |
# File 'lib/chronicle/schema/schema_type.rb', line 59 def ==(other) id == other.id end |
#add_property(property) ⇒ Object
105 106 107 |
# File 'lib/chronicle/schema/schema_type.rb', line 105 def add_property(property) @properties << property unless @properties.include?(property) end |
#add_subtype_id(subtype_id) ⇒ Object
63 64 65 |
# File 'lib/chronicle/schema/schema_type.rb', line 63 def add_subtype_id(subtype_id) @subtype_ids << subtype_id unless @subtype_ids.include?(subtype_id) end |
#all_properties ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/chronicle/schema/schema_type.rb', line 95 def all_properties @all_properties ||= begin properties = @properties.dup ancestors.each do |ancestor| properties.concat(ancestor.properties) end properties end end |
#ancestors ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chronicle/schema/schema_type.rb', line 67 def ancestors @ancestors ||= begin ancestors = [] queue = supertypes.dup until queue.empty? current = queue.shift ancestors << current queue.concat(current.supertypes) end ancestors end end |
#descendants ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/chronicle/schema/schema_type.rb', line 81 def descendants @descendants ||= begin descendants = [] queue = subtypes.dup until queue.empty? current = queue.shift descendants << current queue.concat(current.subtypes) end descendants end end |
#identifier ⇒ Object
FIXME
45 46 47 |
# File 'lib/chronicle/schema/schema_type.rb', line 45 def identifier short_id.to_sym end |
#inspect ⇒ Object
24 25 26 |
# File 'lib/chronicle/schema/schema_type.rb', line 24 def inspect "#<SchemaType:#{id}>" end |
#pretty_print(pp) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/chronicle/schema/schema_type.rb', line 28 def pretty_print(pp) pp.text("SchemaType: #{id}") pp.nest(2) do pp.breakable pp.text("subtypeIds: #{subtype_ids.map(&:id)}") pp.breakable pp.text("Comment: #{comment}") pp.breakable pp.text("Properties: #{properties.map(&:id)}") end end |
#short_id ⇒ Object
40 41 42 |
# File 'lib/chronicle/schema/schema_type.rb', line 40 def short_id id.gsub(@namespace, '') end |
#to_h ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/chronicle/schema/schema_type.rb', line 49 def to_h output = { id:, subtype_ids: } output[:see_also] = @see_also if @see_also output[:comment] = @comment if @comment output end |