Module: Textoken::ConditionalOption

Included in:
Exclude, Only, RegexpOption
Defined in:
lib/textoken/options/modules/conditional_option.rb

Overview

This module will be shared in options like, only and exclude

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



4
5
6
# File 'lib/textoken/options/modules/conditional_option.rb', line 4

def base
  @base
end

#findingsObject (readonly)

Returns the value of attribute findings.



4
5
6
# File 'lib/textoken/options/modules/conditional_option.rb', line 4

def findings
  @findings
end

#regexpsObject (readonly)

Returns the value of attribute regexps.



4
5
6
# File 'lib/textoken/options/modules/conditional_option.rb', line 4

def regexps
  @regexps
end

Instance Method Details

#initialize(values) ⇒ Object



10
11
12
13
# File 'lib/textoken/options/modules/conditional_option.rb', line 10

def initialize(values)
  @regexps  = Searcher.new(values).regexps
  @findings = Findings.new
end

#priorityObject



6
7
8
# File 'lib/textoken/options/modules/conditional_option.rb', line 6

def priority
  1
end

#tokenize_if(&block) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/textoken/options/modules/conditional_option.rb', line 15

def tokenize_if(&block)
  regexps.each do |r|
    base.text.each_with_index do |w, i|
      findings.push(i, w) if block.call(w, r)
    end
  end
  findings.result
end