Class: Lutaml::Turtle::Adapter
- Inherits:
-
Object
- Object
- Lutaml::Turtle::Adapter
- Defined in:
- lib/lutaml/turtle/adapter.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#register ⇒ Object
readonly
Returns the value of attribute register.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data, register: nil) ⇒ Adapter
constructor
A new instance of Adapter.
- #to_turtle(_options = {}) ⇒ Object
Constructor Details
#initialize(data, register: nil) ⇒ Adapter
Returns a new instance of Adapter.
8 9 10 11 |
# File 'lib/lutaml/turtle/adapter.rb', line 8 def initialize(data, register: nil) @data = data @register = register || Lutaml::Model::Config.default_register end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/lutaml/turtle/adapter.rb', line 6 def data @data end |
#register ⇒ Object (readonly)
Returns the value of attribute register.
6 7 8 |
# File 'lib/lutaml/turtle/adapter.rb', line 6 def register @register end |
Class Method Details
.parse(turtle_string, _options = {}) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/lutaml/turtle/adapter.rb', line 13 def self.parse(turtle_string, = {}) require "rdf/turtle" graph = RDF::Graph.new RDF::Turtle::Reader.new(turtle_string).each_statement do |stmt| graph << stmt end graph end |
Instance Method Details
#to_turtle(_options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lutaml/turtle/adapter.rb', line 22 def to_turtle( = {}) require "rdf/turtle" case data when String data when RDF::Enumerable RDF::Turtle::Writer.buffer { |w| data.each_statement { |s| w << s } } else data.to_s end end |