Class: Schemurai::Internal::SchemaNode
- Inherits:
-
Object
- Object
- Schemurai::Internal::SchemaNode
- Defined in:
- lib/schemurai/schema_node.rb
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#dialect ⇒ Object
readonly
Returns the value of attribute dialect.
-
#document_key ⇒ Object
readonly
Returns the value of attribute document_key.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#keyword_mask ⇒ Object
readonly
Returns the value of attribute keyword_mask.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#resource_path ⇒ Object
readonly
Returns the value of attribute resource_path.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#schema_path ⇒ Object
readonly
Returns the value of attribute schema_path.
Instance Method Summary collapse
- #add_child(keyword, segment = MISSING_SEGMENT, child:) ⇒ Object
- #child(keyword, segment = MISSING_SEGMENT) ⇒ Object
- #freeze ⇒ Object
-
#initialize(schema:, dialect:, base_uri:, schema_path:, resource_path:, document_key:) ⇒ SchemaNode
constructor
A new instance of SchemaNode.
Constructor Details
#initialize(schema:, dialect:, base_uri:, schema_path:, resource_path:, document_key:) ⇒ SchemaNode
Returns a new instance of SchemaNode.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/schemurai/schema_node.rb', line 14 def initialize(schema:, dialect:, base_uri:, schema_path:, resource_path:, document_key:) @schema = schema @dialect = dialect @base_uri = base_uri @schema_path = schema_path @resource_path = resource_path @document_key = document_key @keyword_mask = schema.is_a?(Hash) ? dialect.keyword_mask(schema) : 0 @format = Formats.resolve(schema["format"]) if schema.is_a?(Hash) && schema.key?("format") @children = nil end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
10 11 12 |
# File 'lib/schemurai/schema_node.rb', line 10 def base_uri @base_uri end |
#dialect ⇒ Object (readonly)
Returns the value of attribute dialect.
10 11 12 |
# File 'lib/schemurai/schema_node.rb', line 10 def dialect @dialect end |
#document_key ⇒ Object (readonly)
Returns the value of attribute document_key.
10 11 12 |
# File 'lib/schemurai/schema_node.rb', line 10 def document_key @document_key end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
10 11 12 |
# File 'lib/schemurai/schema_node.rb', line 10 def format @format end |
#keyword_mask ⇒ Object (readonly)
Returns the value of attribute keyword_mask.
10 11 12 |
# File 'lib/schemurai/schema_node.rb', line 10 def keyword_mask @keyword_mask end |
#resource ⇒ Object
Returns the value of attribute resource.
12 13 14 |
# File 'lib/schemurai/schema_node.rb', line 12 def resource @resource end |
#resource_path ⇒ Object (readonly)
Returns the value of attribute resource_path.
10 11 12 |
# File 'lib/schemurai/schema_node.rb', line 10 def resource_path @resource_path end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
10 11 12 |
# File 'lib/schemurai/schema_node.rb', line 10 def schema @schema end |
#schema_path ⇒ Object (readonly)
Returns the value of attribute schema_path.
10 11 12 |
# File 'lib/schemurai/schema_node.rb', line 10 def schema_path @schema_path end |
Instance Method Details
#add_child(keyword, segment = MISSING_SEGMENT, child:) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/schemurai/schema_node.rb', line 26 def add_child(keyword, segment = MISSING_SEGMENT, child:) children = (@children ||= {}) if segment.equal?(MISSING_SEGMENT) children[keyword] = child else (children[keyword] ||= {})[segment] = child end end |
#child(keyword, segment = MISSING_SEGMENT) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/schemurai/schema_node.rb', line 35 def child(keyword, segment = MISSING_SEGMENT) return unless @children return @children[keyword] if segment.equal?(MISSING_SEGMENT) @children.dig(keyword, segment) end |
#freeze ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/schemurai/schema_node.rb', line 42 def freeze if @children @children.each_value { |value| value.freeze if value.is_a?(Hash) } @children.freeze end super end |