Sha256: 9111c65d87980635a9e265c68e815275e233e1feeadba0a7a2d6ad7a03bf50cc

Contents?: true

Size: 1.22 KB

Versions: 132

Compression:

Stored size: 1.22 KB

Contents

module Picky

  module Generators

    module Partial

      # The subtoken partial strategy.
      #
      # If given "florian"
      # it will index "floria", "flori", "flor", "flo", "fl", "f"
      # (Depending on what the given from value is, the example is with option from: 1)
      #
      class Infix < Strategy

        attr_reader :min,
                    :max

        # The min option signifies with what size it
        # will start in generating the infix tokens.
        #
        # Examples:
        #
        # With :hello, and max: -1 (default)
        # * min: 1 # => [:hello, :hell, :ello, :hel, :ell, :llo, :he, :el, :ll, :lo, :h, :e, :l, :l, :o]
        # * min: 4 # => [:hello, :hell, :ello]
        #
        # With :hello, and max: -2
        # * min: 1 # => [:hell, :ello, :hel, :ell, :llo, :he, :el, :ll, :lo, :h, :e, :l, :l, :o]
        # * min: 4 # => [:hell, :ello]
        #
        # (min 1 is default)
        #
        def initialize options = {}
          @min = options[:min] || 1
          @max = options[:max] || -1
        end

        # Yields each generated partial.
        #
        def each_partial token, &block
          token.each_intoken min, max, &block
        end

      end

    end

  end

end

Version data entries

132 entries across 132 versions & 1 rubygems

Version Path
picky-4.15.0 lib/picky/generators/partial/infix.rb
picky-4.14.0 lib/picky/generators/partial/infix.rb
picky-4.13.1 lib/picky/generators/partial/infix.rb
picky-4.13.0 lib/picky/generators/partial/infix.rb
picky-4.12.13 lib/picky/generators/partial/infix.rb
picky-4.12.12 lib/picky/generators/partial/infix.rb
picky-4.12.11 lib/picky/generators/partial/infix.rb
picky-4.12.10 lib/picky/generators/partial/infix.rb
picky-4.12.8 lib/picky/generators/partial/infix.rb
picky-4.12.7 lib/picky/generators/partial/infix.rb
picky-4.12.6 lib/picky/generators/partial/infix.rb
picky-4.12.5 lib/picky/generators/partial/infix.rb
picky-4.12.4 lib/picky/generators/partial/infix.rb
picky-4.12.3 lib/picky/generators/partial/infix.rb
picky-4.12.2 lib/picky/generators/partial/infix.rb
picky-4.12.1 lib/picky/generators/partial/infix.rb
picky-4.12.0 lib/picky/generators/partial/infix.rb
picky-4.11.3 lib/picky/generators/partial/infix.rb
picky-4.11.2 lib/picky/generators/partial/infix.rb
picky-4.11.1 lib/picky/generators/partial/infix.rb