Module: Textoken::NumericOption

Included in:
LessThan, MoreThan
Defined in:
lib/textoken/options/modules/numeric_option.rb

Overview

This module will be shared in options like, more_than and less_than

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/numeric_option.rb', line 4

def base
  @base
end

#findingsObject (readonly)

Returns the value of attribute findings.



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

def findings
  @findings
end

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

Instance Method Details

#initialize(value) ⇒ Object



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

def initialize(value)
  validate_option_value(value)
  @number = value
  @findings = Findings.new
end

#priorityObject



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

def priority
  2
end

#tokenize_if(&code) ⇒ Object



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

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

#validate(&code) ⇒ Object



23
24
25
26
27
# File 'lib/textoken/options/modules/numeric_option.rb', line 23

def validate(&code)
  return if code.call
  Textoken.expression_err "value #{number} is not permitted for
    #{self.class.name} option."
end