lib/search_lingo/token.rb in search_lingo-2.0.0 vs lib/search_lingo/token.rb in search_lingo-3.0.0.pre1

- old
+ new

@@ -17,34 +17,31 @@ # Token.new('"foo bar"') # Token.new('foo: bar') # Token.new('foo: "bar baz"') class Token < DelegateClass(String) ## - # Pattern for decomposing a token into a modifier and a term. - STRUCTURE = /\A(?:(#{MODIFIER}):[[:space:]]*)?"?(.+?)"?\z/ - - ## # Returns the modifier portion of the token. Returns +nil+ if token does # not have a modifier. # - # Token.new('foo: bar').modifier # => 'foo' + # Token.new('foo: bar').modifier # => "foo" # Token.new('bar').modifier # => nil def modifier - self[STRUCTURE, 1] + self[SIMPLE_OR_COMPOUND_TOKEN_WITH_GROUPING, 1] end alias operator modifier ## # 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' + # Token.new('foo: bar').term # => "bar" + # Token.new('bar').term # => "bar" + # Token.new('"bar baz"').term # => "bar baz" + # Token.new('""').term # => "" def term - self[STRUCTURE, 2] + self[SIMPLE_OR_COMPOUND_TOKEN_WITH_GROUPING, 2].delete_prefix('"').delete_suffix('"') end ## # Returns +true+ if token has a modifier and +false+ otherwise. # @@ -54,12 +51,12 @@ !modifier.nil? && !modifier.empty? end def inspect # :nodoc: format '#<%<cls>s String(%<str>s) modifier=%<mod>s term=%<term>s>', - cls: self.class, - str: super, - mod: modifier.inspect, - term: term.inspect + cls: self.class, + str: super, + mod: modifier.inspect, + term: term.inspect end end end