Module: Textoken::NumericOption
Overview
This module will be shared in options like, more_than and less_than
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#findings ⇒ Object
readonly
Returns the value of attribute findings.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
- #initialize(value) ⇒ Object
- #priority ⇒ Object
- #tokenize_if(&code) ⇒ Object
- #validate(&code) ⇒ Object
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
4 5 6 |
# File 'lib/textoken/options/modules/numeric_option.rb', line 4 def base @base end |
#findings ⇒ Object (readonly)
Returns the value of attribute findings.
4 5 6 |
# File 'lib/textoken/options/modules/numeric_option.rb', line 4 def findings @findings end |
#number ⇒ Object (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 |
#priority ⇒ Object
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 |