Class: JSON::LD::BlankNodeNamer

Inherits:
BlankNodeMapper show all
Defined in:
lib/json/ld/utils.rb

Instance Method Summary collapse

Methods inherited from BlankNodeMapper

#get_name

Methods inherited from Hash

ordered

Constructor Details

#initialize(prefix) ⇒ BlankNodeNamer

Returns a new instance of BlankNodeNamer.

Parameters:

  • prefix (String)


168
169
170
171
172
# File 'lib/json/ld/utils.rb', line 168

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:

  • (String)


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/json/ld/utils.rb', line 178

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