Class: Stockade::Lexemes::Base
- Inherits:
-
Object
- Object
- Stockade::Lexemes::Base
show all
- Defined in:
- lib/stockade/lexemes/base.rb
Overview
Base class for all lexemes
Lexer extracts lexem candidates of text using ‘.regex` of corresponding= subclass, instantiates it and then furtner calls its `#valid?` to verify that this is indeed a valid lexeme.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(value, start_pos = nil) ⇒ Base
Returns a new instance of Base.
14
15
16
17
|
# File 'lib/stockade/lexemes/base.rb', line 14
def initialize(value, start_pos = nil)
@raw_value = value
@start_pos = start_pos
end
|
Instance Attribute Details
#raw_value ⇒ Object
Returns the value of attribute raw_value.
12
13
14
|
# File 'lib/stockade/lexemes/base.rb', line 12
def raw_value
@raw_value
end
|
#start_pos ⇒ Object
Returns the value of attribute start_pos.
12
13
14
|
# File 'lib/stockade/lexemes/base.rb', line 12
def start_pos
@start_pos
end
|
Class Method Details
.regex ⇒ Object
27
|
# File 'lib/stockade/lexemes/base.rb', line 27
def self.regex; end
|
.types ⇒ Object
54
55
56
|
# File 'lib/stockade/lexemes/base.rb', line 54
def self.types
%i[date word email firstname lastname phone]
end
|
Instance Method Details
#==(other) ⇒ Object
33
34
35
36
|
# File 'lib/stockade/lexemes/base.rb', line 33
def ==(other)
value == other.value &&
self.class == other.class
end
|
#end_pos ⇒ Object
23
24
25
|
# File 'lib/stockade/lexemes/base.rb', line 23
def end_pos
start_pos + raw_value.size
end
|
#mask ⇒ Object
42
43
44
|
# File 'lib/stockade/lexemes/base.rb', line 42
def mask
'*' * raw_value.size
end
|
#range ⇒ Object
38
39
40
|
# File 'lib/stockade/lexemes/base.rb', line 38
def range
start_pos..end_pos
end
|
#token ⇒ Object
46
47
48
|
# File 'lib/stockade/lexemes/base.rb', line 46
def token
SecureRandom.base64(raw_value.size)[0..raw_value.size - 1]
end
|
#type ⇒ Object
50
51
52
|
# File 'lib/stockade/lexemes/base.rb', line 50
def type
self.class.name.split('::').last.downcase.to_sym
end
|
#valid? ⇒ Boolean
29
30
31
|
# File 'lib/stockade/lexemes/base.rb', line 29
def valid?
true
end
|
#value ⇒ Object
19
20
21
|
# File 'lib/stockade/lexemes/base.rb', line 19
def value
raw_value.downcase.strip
end
|