Class: Chronicle::Schema::SchemaProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/chronicle/schema/schema_property.rb

Overview

Represents a property in the RDF graph

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SchemaProperty.

Yields:

  • (_self)

Yield Parameters:



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

#commentObject

Returns the value of attribute comment.



6
7
8
# File 'lib/chronicle/schema/schema_property.rb', line 6

def comment
  @comment
end

#domainObject

Returns the value of attribute domain.



6
7
8
# File 'lib/chronicle/schema/schema_property.rb', line 6

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/chronicle/schema/schema_property.rb', line 5

def id
  @id
end

#manyObject

Returns the value of attribute many.



6
7
8
# File 'lib/chronicle/schema/schema_property.rb', line 6

def many
  @many
end

#namespaceObject

Returns the value of attribute namespace.



6
7
8
# File 'lib/chronicle/schema/schema_property.rb', line 6

def namespace
  @namespace
end

#rangeObject

Returns the value of attribute range.



6
7
8
# File 'lib/chronicle/schema/schema_property.rb', line 6

def range
  @range
end

#range_typesObject

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

#requiredObject

Returns the value of attribute required.



6
7
8
# File 'lib/chronicle/schema/schema_property.rb', line 6

def required
  @required
end

#see_alsoObject

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_identifiersObject



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_snakecaseObject

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

#identifierObject



60
61
62
# File 'lib/chronicle/schema/schema_property.rb', line 60

def identifier
  @id.split('/').last&.to_sym
end

#many?Boolean

Returns:

  • (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_identifiersObject

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

Returns:

  • (Boolean)


52
53
54
# File 'lib/chronicle/schema/schema_property.rb', line 52

def required?
  @required
end

#to_hObject



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