Sha256: cdb5cc0c6c18efcd992b9f220231572eed1a398b51eafd2426b54c45b5b001ab

Contents?: true

Size: 471 Bytes

Versions: 1

Compression:

Stored size: 471 Bytes

Contents

# frozen_string_literal: true
class StoryKey::Generator < StoryKey::Base
  option :bitsize, default: -> {}
  option :format, default: -> {}

  def call
    @bitsize ||= StoryKey::DEFAULT_BITSIZE
    @format ||= StoryKey::DEFAULT_FORMAT

    formatted_str
  end

  private

  def formatted_str
    StoryKey::Coercer.call(str: random_bin, bitsize:, from: :bin, to: format)
  end

  def random_bin
    SecureRandom.hex(bitsize / 8).hex.to_s(2).rjust(bitsize, '0')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
story_key-0.2.0 lib/story_key/generator.rb