Class: JSON::LD::BlankNodeNamer
- Inherits:
-
BlankNodeMapper
- Object
- Hash
- BlankNodeMapper
- JSON::LD::BlankNodeNamer
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/utils.rb
Instance Method Summary collapse
-
#get_sym(old = "") ⇒ String
Get a new symbol mapped from
old
. -
#initialize(prefix) ⇒ BlankNodeNamer
constructor
A new instance of BlankNodeNamer.
Methods inherited from BlankNodeMapper
Methods inherited from Hash
Constructor Details
#initialize(prefix) ⇒ BlankNodeNamer
Returns a new instance of BlankNodeNamer.
285 286 287 288 289 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/utils.rb', line 285 def initialize(prefix) @prefix = prefix.to_s @num = 0 super end |
Instance Method Details
#get_sym(old = "") ⇒ String
Get a new symbol mapped from old
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/utils.rb', line 295 def get_sym(old = "") old = old.to_s.sub(/_:/, '') if !old.empty? && key?(old) self[old] elsif !old.empty? @num += 1 # puts "allocate #{@prefix + (@num - 1).to_s} to #{old.inspect}" self[old] = @prefix + (@num - 1).to_s else # Not referenced, just return a new unique value @num += 1 # puts "allocate #{@prefix + (@num - 1).to_s} to #{old.inspect}" @prefix + (@num - 1).to_s end end |