Class: HumanizedId::Humanizer
- Inherits:
-
Object
- Object
- HumanizedId::Humanizer
- Defined in:
- lib/humanized_id/humanizer.rb
Constant Summary collapse
- SOURCE_CHARSET =
(('0'..'9').to_a + ('a'..'z').to_a).freeze
Instance Method Summary collapse
- #generate_humanized_id ⇒ Object
-
#initialize(id:, min_length: nil, prefix: '') ⇒ Humanizer
constructor
A new instance of Humanizer.
Constructor Details
#initialize(id:, min_length: nil, prefix: '') ⇒ Humanizer
Returns a new instance of Humanizer.
6 7 8 9 10 11 12 |
# File 'lib/humanized_id/humanizer.rb', line 6 def initialize(id:, min_length: nil, prefix: '') @id = id @min_length = min_length @prefix = prefix.to_s @target_charset = CHARSET.join @source_charset = SOURCE_CHARSET.join end |
Instance Method Details
#generate_humanized_id ⇒ Object
14 15 16 17 |
# File 'lib/humanized_id/humanizer.rb', line 14 def generate_humanized_id new_id = resize convert_to_target_charset convert_to_target_base(@id) "#{@prefix}#{new_id}" end |