lib/propertybase_id.rb in propertybase_id-0.5.0 vs lib/propertybase_id.rb in propertybase_id-0.6.0

- old
+ new

@@ -2,81 +2,69 @@ require "propertybase_id/generator" require "propertybase_id/mappings" class PropertybaseId attr_reader :object_id - attr_reader :host_id attr_reader :time - attr_reader :process_id - attr_reader :counter + attr_reader :random_int - def initialize(object_id:, host_id:, time:, process_id:, counter:) + def initialize(object_id:, time:, random_int:) @object_id = object_id - @host_id = host_id @time = time - @process_id = process_id - @counter = counter + @random_int = random_int end def object @_object ||= self.class.team_from_object_id(@object_id || "") end def to_s @_string ||= begin - object_str = format_number(@object_id, 3) - host_str = format_number(@host_id, 2) - time_str = format_number(@time, 6) - process_str = format_number(@process_id, 2) - counter_str = format_number(@counter, 5) + object_str = format_number(@object_id, 2) + time_str = format_number(@time, 7) + random_str = format_number(@random_int, 6) - "#{object_str}#{host_str}#{time_str}#{process_str}#{counter_str}" + "#{object_str}#{time_str}#{random_str}" end end def ==(o) self.class == o.class && self.object_id == o.object_id && - self.host_id == o.host_id && - self.process_id == o.process_id && self.time == o.time && - self.counter == o.counter + self.random_int == o.random_int end alias_method :eql?, :== def hash [ object_id, - host_id, time, - process_id, - counter, + random_int, ].hash end def self.generate(object:) @@generator.generate(object: object) end def self.parse(input_id) raise ArgumentError, "invalid length (#{input_id.size})" if input_id.size != max_length - _, object_id, host_id, time, process_id, counter = input_id.match(/(\w{3})(\w{2})(\w{6})(\w{2})(\w{5})/).to_a + _, object_id, time, random_str = input_id.match(/(\w{2})(\w{7})(\w{6})/).to_a team_from_object_id(object_id.to_i(36)) new( object_id: object_id.to_i(36), - host_id: host_id.to_i(36), time: time.to_i(36), - process_id: process_id.to_i(36), - counter: counter.to_i(36), + random_int: random_str.to_i(36), ) end def self.max_length - 18 + 15 end def self.max_value(digits = max_length) ("z" * digits).to_i(36) end