Sha256: 29ca65e348247579728d41f22562d8a62f99e687946c1de8c0f0821afbe013aa

Contents?: true

Size: 888 Bytes

Versions: 1

Compression:

Stored size: 888 Bytes

Contents

module GuessWhoNoFuzzy
  class Tokenizer
    def self.tokenize!(str)
      self.new(str).tokenize!
    end

    def initialize(str)
      @str = str
    end

    def tokenize!
      token_arrays = []
      str_size = @str.size

      str_size.times do |i|
        first_slice = i + 1
        first_name = @str.slice(0, first_slice)

        (str_size - i).times do |j|
          mid_slice = j + 1
          mid_name = @str.slice(first_slice, mid_slice)

          last_slice = first_slice + mid_slice
          last_name = @str.slice(last_slice...str_size)

          token_array = [first_name]
          token_array << mid_name unless blank?(mid_name)
          token_array << last_name unless blank?(last_name)
          token_arrays << token_array
        end
      end

      token_arrays
    end

    private

    def blank?(token)
      token.nil? || token.empty?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guess_who_no_fuzzy-0.2.0 lib/guess_who_no_fuzzy/tokenizer.rb