Class: Orientdb::RecordId

Inherits:
Object
  • Object
show all
Defined in:
lib/orientdb_binary/record_id.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rid = nil) ⇒ RecordId

Returns a new instance of RecordId.



7
8
9
10
11
12
13
14
15
16
# File 'lib/orientdb_binary/record_id.rb', line 7

def initialize(rid=nil)
  @cluster = nil
  @position = nil
  if rid.is_a? String and not rid.empty?
    parse_rid(rid)
  elsif rid.is_a? Orientdb::RecordId
    @cluster = rid.cluster
    @position = rid.position
  end
end

Instance Attribute Details

#clusterObject

Returns the value of attribute cluster.



3
4
5
# File 'lib/orientdb_binary/record_id.rb', line 3

def cluster
  @cluster
end

#positionObject

Returns the value of attribute position.



3
4
5
# File 'lib/orientdb_binary/record_id.rb', line 3

def position
  @position
end

Instance Method Details

#==(o) ⇒ Object



33
34
35
# File 'lib/orientdb_binary/record_id.rb', line 33

def ==(o)
  o.class == self.class && o.cluster == self.cluster && o.position == self.position
end

#eql?Object



5
# File 'lib/orientdb_binary/record_id.rb', line 5

alias_method :eql?, :==

#parse_rid(rid) ⇒ Object



18
19
20
21
22
23
# File 'lib/orientdb_binary/record_id.rb', line 18

def parse_rid(rid)
  match = rid.match(/^[#]?(?<cluster>-?\d+):(?<position>\d+)$/)
  @cluster = match[:cluster].to_i
  @position = match[:position].to_i
  self
end

#temporary?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/orientdb_binary/record_id.rb', line 29

def temporary?
  @cluster < 0
end

#to_sObject



25
26
27
# File 'lib/orientdb_binary/record_id.rb', line 25

def to_s
  "##{cluster}:#{position}"
end