class SearchLingo::Token
Single token from a query string. A token consists of a term an an optional modifier. The term may be a word or multiple words contained within double quotes. The modifier is one or more alphanumeric characters. The modifier and term and separated by a colon followed by zero or more whitespace characters.
The following are examples of tokens:
Token.new('foo') Token.new('"foo bar"') Token.new('foo: bar') Token.new('foo: "bar baz"')
Constants
- STRUCTURE
Pattern for decomposing a token into a modifier and a term.
Public Instance Methods
compound?()
click to toggle source
Returns true
if token has a modifier and false
otherwise.
Token.new('foo: bar').compound? # => true Token.new('bar').compound? # => false
# File lib/search_lingo/token.rb, line 53 def compound? !modifier.nil? && !modifier.empty? end
modifier()
click to toggle source
Returns the modifier portion of the token. Returns nil
if token does not have a modifier.
Token.new('foo: bar').modifier # => 'foo' Token.new('bar').modifier # => nil
# File lib/search_lingo/token.rb, line 31 def modifier self[STRUCTURE, 1] end
Also aliased as: operator
term()
click to toggle source
Returns the term portion of the token. If the term is wrapped in quotes, they are removed.
Token.new('foo: bar').term # => 'bar' Token.new('bar').term # => 'bar' Token.new('"bar baz"').term # => 'bar baz'
# File lib/search_lingo/token.rb, line 44 def term self[STRUCTURE, 2] end