Sha256: 8e1af76b0534e087c4472b221f5cdbf7b6530ea876a6a6ef1857285755748066

Contents?: true

Size: 679 Bytes

Versions: 6

Compression:

Stored size: 679 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

6 entries across 6 versions & 1 rubygems

Version Path
squib-0.19.0 lib/squib/graphics/embedding_utils.rb
squib-0.19.0b lib/squib/graphics/embedding_utils.rb
squib-0.19.0a lib/squib/graphics/embedding_utils.rb
squib-0.15.2 lib/squib/graphics/embedding_utils.rb
squib-0.15.1 lib/squib/graphics/embedding_utils.rb
squib-0.14.2 lib/squib/graphics/embedding_utils.rb