Sha256: 77b0d32e33db7338103cd145601f78ea3cb17da1f9a771926945ac6090812baa

Contents?: true

Size: 923 Bytes

Versions: 2

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

require "masososo/version"
require "masososo/similar_char_sets"
require "masososo/indexer"

module Masososo
  class Error < StandardError; end

  class << self
    def similar_chars(char, including_self: false, **)
      raise 'A character instead of a string' if char.size != 1

      if including_self
        @@similar_char_index_including_self[char] || [char]
      else
        @@similar_char_index[char] || [char]
      end
    end

    def similar_string(str, including_self: false, frequency: 0.5, **)
      str.chars.map do |char|
        if rand < frequency
          similar_chars(char, including_self: including_self).sample
        else
          char
        end
      end.join('')
    end

    @@similar_char_index = Indexer.index(SIMILAR_CHAR_SETS, false)
    @@similar_char_index_including_self = Indexer.index(SIMILAR_CHAR_SETS, true)
  end
end

require 'masososo/core_ext'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
masososo-0.0.3 lib/masososo.rb
masososo-0.0.2 lib/masososo.rb