Class: Chronicle::Schema::SchemaProperty
- Inherits:
-
Object
- Object
- Chronicle::Schema::SchemaProperty
- Defined in:
- lib/chronicle/schema/schema_property.rb
Overview
Represents a property in the RDF graph
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#many ⇒ Object
Returns the value of attribute many.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#range ⇒ Object
Returns the value of attribute range.
-
#range_types ⇒ Object
Returns the value of attribute range_types.
-
#required ⇒ Object
Returns the value of attribute required.
-
#see_also ⇒ Object
Returns the value of attribute see_also.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #full_range_identifiers ⇒ Object
-
#id_snakecase ⇒ Object
FIXME.
- #identifier ⇒ Object
-
#initialize(id) {|_self| ... } ⇒ SchemaProperty
constructor
A new instance of SchemaProperty.
- #many? ⇒ Boolean
- #pretty_print(pp) ⇒ Object
-
#range_identifiers ⇒ Object
FIXME: refactor this and the next.
- #required? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(id) {|_self| ... } ⇒ SchemaProperty
Returns a new instance of SchemaProperty.
15 16 17 18 19 20 21 22 23 |
# File 'lib/chronicle/schema/schema_property.rb', line 15 def initialize(id) @id = id @domain = [] @range = [] @many = false @required = false yield self if block_given? end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
6 7 8 |
# File 'lib/chronicle/schema/schema_property.rb', line 6 def comment @comment end |
#domain ⇒ Object
Returns the value of attribute domain.
6 7 8 |
# File 'lib/chronicle/schema/schema_property.rb', line 6 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/chronicle/schema/schema_property.rb', line 5 def id @id end |
#many ⇒ Object
Returns the value of attribute many.
6 7 8 |
# File 'lib/chronicle/schema/schema_property.rb', line 6 def many @many end |
#namespace ⇒ Object
Returns the value of attribute namespace.
6 7 8 |
# File 'lib/chronicle/schema/schema_property.rb', line 6 def namespace @namespace end |
#range ⇒ Object
Returns the value of attribute range.
6 7 8 |
# File 'lib/chronicle/schema/schema_property.rb', line 6 def range @range end |
#range_types ⇒ Object
Returns the value of attribute range_types.
6 7 8 |
# File 'lib/chronicle/schema/schema_property.rb', line 6 def range_types @range_types end |
#required ⇒ Object
Returns the value of attribute required.
6 7 8 |
# File 'lib/chronicle/schema/schema_property.rb', line 6 def required @required end |
#see_also ⇒ Object
Returns the value of attribute see_also.
6 7 8 |
# File 'lib/chronicle/schema/schema_property.rb', line 6 def see_also @see_also end |
Instance Method Details
#==(other) ⇒ Object
48 49 50 |
# File 'lib/chronicle/schema/schema_property.rb', line 48 def ==(other) id == other.id end |
#full_range_identifiers ⇒ Object
76 77 78 |
# File 'lib/chronicle/schema/schema_property.rb', line 76 def full_range_identifiers range_types.map(&:descendants).flatten.map { |x| x.id.split('/').last&.to_sym } + range_identifiers end |
#id_snakecase ⇒ Object
FIXME
65 66 67 |
# File 'lib/chronicle/schema/schema_property.rb', line 65 def id_snakecase @id.split('/').last.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase.to_sym end |
#identifier ⇒ Object
60 61 62 |
# File 'lib/chronicle/schema/schema_property.rb', line 60 def identifier @id.split('/').last&.to_sym end |
#many? ⇒ Boolean
56 57 58 |
# File 'lib/chronicle/schema/schema_property.rb', line 56 def many? @many end |
#pretty_print(pp) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/chronicle/schema/schema_property.rb', line 25 def pretty_print(pp) pp.text("SchemaProperty: #{id}") pp.nest(2) do pp.breakable pp.text("Range: #{range}") pp.breakable pp.text("Domain: #{domain}") end end |
#range_identifiers ⇒ Object
FIXME: refactor this and the next
70 71 72 73 74 |
# File 'lib/chronicle/schema/schema_property.rb', line 70 def range_identifiers range.map do |r| r.split('/').last&.to_sym end end |
#required? ⇒ Boolean
52 53 54 |
# File 'lib/chronicle/schema/schema_property.rb', line 52 def required? @required end |
#to_h ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/chronicle/schema/schema_property.rb', line 35 def to_h output = { id:, domain:, range:, many: @many, required: @required } output[:comment] = @comment if @comment output[:see_also] = @see_also if @see_also output end |