Class: ZergXcode::IdGenerator
- Inherits:
-
Object
- Object
- ZergXcode::IdGenerator
- Defined in:
- lib/zerg_xcode/file_format/id_generator.rb
Overview
Generates archive IDs for objects.
Instance Method Summary collapse
- #id_for(object) ⇒ Object
-
#initialize ⇒ IdGenerator
constructor
A new instance of IdGenerator.
- #new_id ⇒ Object
Constructor Details
#initialize ⇒ IdGenerator
Returns a new instance of IdGenerator.
7 8 9 |
# File 'lib/zerg_xcode/file_format/id_generator.rb', line 7 def initialize @assigned_ids = Set.new end |
Instance Method Details
#id_for(object) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/zerg_xcode/file_format/id_generator.rb', line 20 def id_for(object) if object.archive_id && !@assigned_ids.include?(object.archive_id) @assigned_ids << object.archive_id return object.archive_id else return new_id end end |
#new_id ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/zerg_xcode/file_format/id_generator.rb', line 11 def new_id loop do id = (0...24).map { '%02X' % rand(256) }.join next if @assigned_ids.include? id @assigned_ids << id return id end end |