Class: BEL::Translator::Plugins::BelScript::Reader

Inherits:
Object
  • Object
show all
Includes:
BELParser::Script
Defined in:
lib/bel/translator/plugins/bel_script/reader.rb

Constant Summary collapse

SyntaxError =
::BELParser::Language::Syntax::SyntaxError

Instance Method Summary collapse

Constructor Details

#initialize(io, options = {}) ⇒ Reader

Returns a new instance of Reader.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bel/translator/plugins/bel_script/reader.rb', line 12

def initialize(io, options = {})
  @io    = io

  options = {
    :language => '1.0'
  }.merge(options)

  @state = {
    uri_reader:            BELParser::Resource.default_uri_reader,
    url_reader:            BELParser::Resource.default_url_reader,
    specification:         BELParser::Language.specification(options[:language]),
    namespace_definitions: {}
  }.merge(options)
end

Instance Method Details

#eachObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bel/translator/plugins/bel_script/reader.rb', line 27

def each
  if block_given?
    NanopubMapper.new(
      Validator.new(
        StateAggregator.new(
          FirstNode.new(Filter.new(BELParser::ASTGenerator.new(@io))),
          @state))
    ).each do |(num, line, ast_node, nanopub_hash)|
      yield ::BEL::Nanopub::Nanopub.create(nanopub_hash)
    end
  else
    enum_for(:each)
  end
end