Class: Chronicle::Schema::SchemaType

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(id) {|_self| ... } ⇒ SchemaType

Returns a new instance of SchemaType.

Yields:

  • (_self)

Yield Parameters:



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

#commentObject

Returns the value of attribute comment.



8
9
10
# File 'lib/chronicle/schema/schema_type.rb', line 8

def comment
  @comment
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/chronicle/schema/schema_type.rb', line 7

def id
  @id
end

#namespaceObject

Returns the value of attribute namespace.



8
9
10
# File 'lib/chronicle/schema/schema_type.rb', line 8

def namespace
  @namespace
end

#propertiesObject

Returns the value of attribute properties.



8
9
10
# File 'lib/chronicle/schema/schema_type.rb', line 8

def properties
  @properties
end

#see_alsoObject

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_idsObject

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

#subtypesObject

Returns the value of attribute subtypes.



8
9
10
# File 'lib/chronicle/schema/schema_type.rb', line 8

def subtypes
  @subtypes
end

#supertypesObject

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_propertiesObject



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

#ancestorsObject



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

#descendantsObject



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

#identifierObject

FIXME



45
46
47
# File 'lib/chronicle/schema/schema_type.rb', line 45

def identifier
  short_id.to_sym
end

#inspectObject



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_idObject



40
41
42
# File 'lib/chronicle/schema/schema_type.rb', line 40

def short_id
  id.gsub(@namespace, '')
end

#to_hObject



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