Class: Picky::Generators::Partial::SubstringGenerator

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

Overview

Generates the right substrings for use in the substring strategy.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to) ⇒ SubstringGenerator

Returns a new instance of SubstringGenerator.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/picky/generators/partial/substring.rb', line 13

def initialize from, to
  @from, @to = from, to

  if @to.zero?
    def each_subtoken token, &block
      token.each_subtoken @from, &block
    end
  else
    if @from < 0 && @to < 0
      def each_subtoken token, &block
        token.each_subtoken @from - @to - 1, (0..@to), &block
      end
    else
      def each_subtoken token, &block
        token.each_subtoken @from, (0..@to), &block
      end
    end
  end

end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



11
12
13
# File 'lib/picky/generators/partial/substring.rb', line 11

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



11
12
13
# File 'lib/picky/generators/partial/substring.rb', line 11

def to
  @to
end