Class: Picky::Generators::Partial::Substring

Inherits:
Strategy show all
Defined in:
lib/picky/generators/partial/substring.rb

Overview

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)

Direct Known Subclasses

Postfix

Instance Method Summary collapse

Methods inherited from Strategy

#use_exact_for_partial?

Methods inherited from Strategy

#saved?, #to_s

Constructor Details

#initialize(options = {}) ⇒ Substring

The from option signifies where in the symbol it will start in generating the subtokens.

Examples:

With :hello, and to: -1 (default)

  • from: 1 # => [:hello, :hell, :hel, :he, :h]

  • from: 4 # => [:hello, :hell]

With :hello, and to: -2

  • from: 1 # => [:hell, :hel, :he, :h]

  • from: 4 # => [:hell]



57
58
59
60
61
# File 'lib/picky/generators/partial/substring.rb', line 57

def initialize options = {}
  from = options[:from] || 1
  to   = options[:to]   || -1
  @generator = SubstringGenerator.new from, to
end

Instance Method Details

#each_partial(token, &block) ⇒ Object

Yields each generated partial.



77
78
79
# File 'lib/picky/generators/partial/substring.rb', line 77

def each_partial token, &block
  @generator.each_subtoken token, &block
end

#fromObject

Delegator to generator#from.



65
66
67
# File 'lib/picky/generators/partial/substring.rb', line 65

def from
  @generator.from
end

#toObject

Delegator to generator#to.



71
72
73
# File 'lib/picky/generators/partial/substring.rb', line 71

def to
  @generator.to
end