Class: Dtmcli::IdGenerator
- Inherits:
-
Object
- Object
- Dtmcli::IdGenerator
- Defined in:
- lib/dtmcli/id_generator.rb
Instance Attribute Summary collapse
-
#branch_id ⇒ Object
Returns the value of attribute branch_id.
-
#id_gen ⇒ Object
readonly
Returns the value of attribute id_gen.
-
#parent_id ⇒ Object
Returns the value of attribute parent_id.
Class Method Summary collapse
Instance Method Summary collapse
- #gen_branch_id ⇒ Object
-
#initialize(parent_id = nil, branch_id = nil) ⇒ IdGenerator
constructor
A new instance of IdGenerator.
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_id ⇒ Object
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_gen ⇒ Object (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_id ⇒ Object
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
Instance Method Details
#gen_branch_id ⇒ Object
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 |