Class: Dtmcli::IdGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/dtmcli/id_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_id = nil, branch_id = nil) ⇒ IdGenerator

Returns a new instance of IdGenerator.



12
13
14
15
# File 'lib/dtmcli/id_generator.rb', line 12

def initialize(parent_id=nil, branch_id=nil)
  @parent_id = parent_id || ''
  @branch_id = branch_id || 0
end

Instance Attribute Details

#branch_idObject

Returns the value of attribute branch_id.



4
5
6
# File 'lib/dtmcli/id_generator.rb', line 4

def branch_id
  @branch_id
end

#id_genObject (readonly)

Returns the value of attribute id_gen.



3
4
5
# File 'lib/dtmcli/id_generator.rb', line 3

def id_gen
  @id_gen
end

#parent_idObject

Returns the value of attribute parent_id.



4
5
6
# File 'lib/dtmcli/id_generator.rb', line 4

def parent_id
  @parent_id
end

Class Method Details

.gen_gid(dtm_url) ⇒ Object



7
8
9
# File 'lib/dtmcli/id_generator.rb', line 7

def gen_gid(dtm_url)
  return Dtm.new_gid(dtm_url)
end

Instance Method Details

#gen_branch_idObject



17
18
19
20
21
22
# File 'lib/dtmcli/id_generator.rb', line 17

def gen_branch_id
  raise 'branch id is lager than 99' if branch_id >= 99
  raise 'total branch id is longer than 20' if parent_id.size >= 20
  @branch_id = branch_id + 1
  return "#{parent_id}#{branch_id}"
end