Class: JSON::LD::BlankNodeNamer

Inherits:
BlankNodeMapper show all
Defined in:
vendor/bundler/ruby/2.4.0/bundler/gems/json-ld-4e9cdb2fc35e/lib/json/ld/utils.rb

Instance Method Summary collapse

Methods inherited from BlankNodeMapper

#get_name

Methods inherited from Hash

#to_sxp, #to_sxp_bin

Constructor Details

#initialize(prefix) ⇒ BlankNodeNamer

Returns a new instance of BlankNodeNamer

Parameters:



266
267
268
269
270
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/json-ld-4e9cdb2fc35e/lib/json/ld/utils.rb', line 266

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

Parameters:

  • old (String) (defaults to: "")

    ("")

Returns:



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/json-ld-4e9cdb2fc35e/lib/json/ld/utils.rb', line 276

def get_sym(old = "")
  old = old.to_s.sub(/_:/, '')
  if !old.empty? && self.has_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