Class: BELParser::Script::State::NamespaceDefinition

Inherits:
Object
  • Object
show all
Extended by:
BELParser::Script::StateFunction
Defined in:
lib/bel_parser/script/state/namespace_definition.rb

Constant Summary collapse

TARGET_NODE =
BELParser::Parsers::AST::NamespaceDefinition

Class Method Summary collapse

Methods included from BELParser::Script::StateFunction

consume

Class Method Details

.consume(ast_node, script_context) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bel_parser/script/state/namespace_definition.rb', line 16

def self.consume(ast_node, script_context)
  return nil unless ast_node.is_a?(TARGET_NODE)
  uri_reader = script_context[:uri_reader]
  url_reader = script_context[:url_reader]

  keyword, domain = ast_node.children
  keyword_s       = keyword.identifier.string_literal

  case
  when domain.uri?
    uri     = domain.child.string.string_literal
    dataset = uri_reader.retrieve_resource(uri)
    script_context[:namespace_definitions] ||= Concurrent::Hash.new
    script_context[:namespace_definitions][keyword_s] =
      BELParser::Expression::Model::Namespace.new(
        keyword_s,
        uri,
        nil)
  when domain.url?
    ApplyResourceURI.new.process(ast_node)
    if ast_node.uri
      dataset = uri_reader.retrieve_resource(ast_node.uri)
      script_context[:namespace_definitions] ||= Concurrent::Hash.new
      script_context[:namespace_definitions][keyword_s] =
        BELParser::Expression::Model::Namespace.new(
          keyword_s,
          ast_node.uri,
          domain.child.string.string_literal)
    else
      url     = domain.child.string.string_literal
      dataset = url_reader.retrieve_resource(url)
      script_context[:namespace_definitions] ||= Concurrent::Hash.new
      script_context[:namespace_definitions][keyword_s] =
        BELParser::Expression::Model::Namespace.new(
          keyword_s,
          nil,
          url)
    end
  end
end