Sha256: 5b2fdf5afd42b10504d11b5f58245e5848c5e7af113c54d7b7bfd29c019cfadf

Contents?: true

Size: 707 Bytes

Versions: 20

Compression:

Stored size: 707 Bytes

Contents

module Squib
  class EmbeddingUtils

    # Given a string and a bunch of keys, give us back a mapping of those keys
    # to where those keys start, and where they end (in ranges)
    #
    # See the spec for expected outputs
    def self.indices(str, keys)
      map = {}
      keys.each do |key|
        map[key] ||= []
        start = 0
        while true
          idx = str.index(key, start)
          if idx.nil?
            break; # done searching
          else
            idx_bytes = str[0..idx].bytesize - 1
            map[key] << (idx_bytes..(idx_bytes + key.size))
            start = idx + 1
          end
        end
      end
      return map
    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
squib-0.18.0 lib/squib/graphics/embedding_utils.rb
squib-0.17.2 lib/squib/graphics/embedding_utils.rb
squib-0.17.1 lib/squib/graphics/embedding_utils.rb
squib-0.17.0 lib/squib/graphics/embedding_utils.rb
squib-0.16.0 lib/squib/graphics/embedding_utils.rb
squib-0.16.0.pre.preview2 lib/squib/graphics/embedding_utils.rb
squib-0.16.0.pre.preview1 lib/squib/graphics/embedding_utils.rb
squib-0.15.3 lib/squib/graphics/embedding_utils.rb
squib-0.15.0 lib/squib/graphics/embedding_utils.rb
squib-0.14.3.pre1 lib/squib/graphics/embedding_utils.rb
squib-0.14.1 lib/squib/graphics/embedding_utils.rb
squib-0.14.0 lib/squib/graphics/embedding_utils.rb
squib-0.14.beta1 lib/squib/graphics/embedding_utils.rb
squib-0.13.4 lib/squib/graphics/embedding_utils.rb
squib-0.13.3 lib/squib/graphics/embedding_utils.rb
squib-0.13.2 lib/squib/graphics/embedding_utils.rb
squib-0.13.1 lib/squib/graphics/embedding_utils.rb
squib-0.13.0 lib/squib/graphics/embedding_utils.rb
squib-0.12.0 lib/squib/graphics/embedding_utils.rb
squib-0.11.0 lib/squib/graphics/embedding_utils.rb