Class: Hayfork::QueryParser
- Inherits:
-
Object
- Object
- Hayfork::QueryParser
- Defined in:
- lib/hayfork/query_parser.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#querystring ⇒ Object
readonly
Returns the value of attribute querystring.
Instance Method Summary collapse
-
#initialize(klass, querystring) ⇒ QueryParser
constructor
A new instance of QueryParser.
- #parse! ⇒ Object
- #parse_exact_phrase(querystring, phrases) ⇒ Object
- #parse_phrase(querystring, phrases) ⇒ Object
Constructor Details
#initialize(klass, querystring) ⇒ QueryParser
Returns a new instance of QueryParser.
5 6 7 8 |
# File 'lib/hayfork/query_parser.rb', line 5 def initialize(klass, querystring) @klass = klass @querystring = querystring end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/hayfork/query_parser.rb', line 3 def klass @klass end |
#querystring ⇒ Object (readonly)
Returns the value of attribute querystring.
3 4 5 |
# File 'lib/hayfork/query_parser.rb', line 3 def querystring @querystring end |
Instance Method Details
#parse! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hayfork/query_parser.rb', line 10 def parse! phrases = [] scanner = StringScanner.new(Hayfork.unaccent(querystring)) until scanner.eos? parse_phrase(scanner.scan(/[^"]+/), phrases) break if scanner.eos? scanner.getch # " parse_exact_phrase(scanner.scan(/[^"]+/), phrases) scanner.getch # " end klass.new(phrases) end |
#parse_exact_phrase(querystring, phrases) ⇒ Object
30 31 32 |
# File 'lib/hayfork/query_parser.rb', line 30 def parse_exact_phrase(querystring, phrases) raise NotImplementedError end |
#parse_phrase(querystring, phrases) ⇒ Object
26 27 28 |
# File 'lib/hayfork/query_parser.rb', line 26 def parse_phrase(querystring, phrases) raise NotImplementedError end |