class TurtleReader

Constants

NS
VERSION

Attributes

base[R]
file[RW]
map[R]
prefixes[R]
reader[R]

Public Class Methods

foreach(file, *args, &block) click to toggle source
# File lib/turtle_reader.rb, line 50
def foreach(file, *args, &block)
  open(file, *args) { |turtle| turtle.each(&block) }
end
new(reader, map = true) click to toggle source
# File lib/turtle_reader.rb, line 56
def initialize(reader, map = true)
  @reader, @base, @prefixes = reader, *reader.parse_prologue
  self.map = map
end
open(file, *args) { |turtle| ... } click to toggle source
# File lib/turtle_reader.rb, line 41
def open(file, *args)
  RDF::Reader.open(file, format: :ttl) { |reader|
    turtle = new(reader, *args)
    turtle.file = File.expand_path(file)

    return block_given? ? yield(turtle) : turtle
  }
end

Public Instance Methods

closed?() click to toggle source
# File lib/turtle_reader.rb, line 106
def closed?
  reader.closed?
end
each() { |s, o, k| ... } click to toggle source
# File lib/turtle_reader.rb, line 92
def each
  return enum_for(__method__) unless block_given?

  uri, map, base = RDF::URI, self.map, self.base

  each_statement { |t|
    s, p, o = *t

    if s.is_a?(uri) and k = map[p] and s.start_with?(base)
      yield s, o, k
    end
  }
end
each_statement(&block) click to toggle source
# File lib/turtle_reader.rb, line 86
def each_statement(&block)
  return enum_for(__method__) unless block_given?
  reader.parse_statements(&block)
  self
end
inspect() click to toggle source
# File lib/turtle_reader.rb, line 110
def inspect
  '#<%s:0x%x @file=%p, @base=%p%s>' % [
    self.class, object_id, file, base, closed? ? ' (closed)' : ''
  ]
end
map=(map) click to toggle source
# File lib/turtle_reader.rb, line 65
def map=(map)
  unless map.is_a?(Hash)
    @map = Hash.new(map)
  else
    @map = {}

    map.each { |k, v|
      if k.is_a?(String)
        n, s = k.split(':', 2)
        k = NS.key?(n = n.to_sym) ? NS[n][s] : prefixes[n] / s
      end

      @map[k] = v
    }
  end
end
statements() click to toggle source
# File lib/turtle_reader.rb, line 82
def statements
  each_statement.to_a
end