Class: DynamicLinks::ShorteningStrategies::NanoIDStrategy

Inherits:
BaseStrategy
  • Object
show all
Defined in:
lib/dynamic_links/shortening_strategies/nano_id_strategy.rb

Overview

Shortens the given URL using Nano ID This strategy will generate a different short URL for the same given URL

Constant Summary

Constants inherited from BaseStrategy

BaseStrategy::BASE62_CHARS, BaseStrategy::MIN_LENGTH

Instance Method Summary collapse

Instance Method Details

#always_growing?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/dynamic_links/shortening_strategies/nano_id_strategy.rb', line 13

def always_growing?
  true  # This strategy always generates a new shortened URL
end

#shorten(url, min_length: MIN_LENGTH) ⇒ Object

Shortens the given URL using Nano ID

Parameters:

  • url (String)

    The URL to shorten (not directly used in Nano ID strategy)

  • min_length (Integer) (defaults to: MIN_LENGTH)

    The size (length) of the generated Nano ID



9
10
11
# File 'lib/dynamic_links/shortening_strategies/nano_id_strategy.rb', line 9

def shorten(url, min_length: MIN_LENGTH)
  ::Nanoid.generate(size: min_length)
end