Class: Nuggets::RDF::Turtle
- Includes:
- Enumerable
- Defined in:
- lib/nuggets/rdf/turtle.rb
Constant Summary collapse
- NS_SEPARATOR =
':'.freeze
- NS =
::RDF::Vocabulary.inject({}) { |h, v| h[v.__prefix__] = v; h }
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#file ⇒ Object
Returns the value of attribute file.
-
#map ⇒ Object
Returns the value of attribute map.
-
#prefixes ⇒ Object
readonly
Returns the value of attribute prefixes.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
Class Method Summary collapse
Instance Method Summary collapse
- #closed? ⇒ Boolean
- #each ⇒ Object
- #each_statement(&block) ⇒ Object
-
#initialize(reader, map = true) ⇒ Turtle
constructor
A new instance of Turtle.
- #inspect ⇒ Object
- #statements ⇒ Object
Methods included from Enumerable
#_nuggets_original_all?, #_nuggets_original_any?, #_nuggets_original_max, #_nuggets_original_max_by, #_nuggets_original_min, #_nuggets_original_min_by, #_nuggets_original_minmax, #_nuggets_original_minmax_by, #agrep, #all?, #any?, #max, #max_by, #min, #min_by, #minmax, #minmax_by
Constructor Details
#initialize(reader, map = true) ⇒ Turtle
62 63 64 65 |
# File 'lib/nuggets/rdf/turtle.rb', line 62 def initialize(reader, map = true) @reader, @base, @prefixes = reader, *reader.parse_prologue self.map = map end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
67 68 69 |
# File 'lib/nuggets/rdf/turtle.rb', line 67 def base @base end |
#file ⇒ Object
Returns the value of attribute file.
69 70 71 |
# File 'lib/nuggets/rdf/turtle.rb', line 69 def file @file end |
#map ⇒ Object
Returns the value of attribute map.
67 68 69 |
# File 'lib/nuggets/rdf/turtle.rb', line 67 def map @map end |
#prefixes ⇒ Object (readonly)
Returns the value of attribute prefixes.
67 68 69 |
# File 'lib/nuggets/rdf/turtle.rb', line 67 def prefixes @prefixes end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
67 68 69 |
# File 'lib/nuggets/rdf/turtle.rb', line 67 def reader @reader end |
Class Method Details
.foreach(file, *args, &block) ⇒ Object
56 57 58 |
# File 'lib/nuggets/rdf/turtle.rb', line 56 def foreach(file, *args, &block) open(file, *args) { |turtle| turtle.each(&block) } end |
Instance Method Details
#closed? ⇒ Boolean
112 113 114 |
# File 'lib/nuggets/rdf/turtle.rb', line 112 def closed? reader.closed? end |
#each ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/nuggets/rdf/turtle.rb', line 98 def each return enum_for(:each) 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) ⇒ Object
92 93 94 95 96 |
# File 'lib/nuggets/rdf/turtle.rb', line 92 def each_statement(&block) return enum_for(:each_statement) unless block_given? reader.parse_statements(&block) self end |
#inspect ⇒ Object
116 117 118 119 120 |
# File 'lib/nuggets/rdf/turtle.rb', line 116 def inspect '#<%s:0x%x @file=%p, @base=%p%s>' % [ self.class, object_id, file, base, closed? ? ' (closed)' : '' ] end |
#statements ⇒ Object
88 89 90 |
# File 'lib/nuggets/rdf/turtle.rb', line 88 def statements each_statement.to_a end |