class Honyomi::Query
Constants
- OPTIONS
Attributes
bookmark_query[R]
jump_page_no[R]
key[R]
page_query[R]
src[R]
Public Class Methods
new(src)
click to toggle source
# File lib/honyomi/query.rb, line 16 def initialize(src) @src = src init_hash parse end
Private Instance Methods
init_hash()
click to toggle source
# File lib/honyomi/query.rb, line 24 def init_hash @key = {} OPTIONS.flatten.each do |key| @key[key] = [] end end
make_query(minus, text, key = nil)
click to toggle source
# File lib/honyomi/query.rb, line 77 def make_query(minus, text, key = nil) m = minus ? "-" : "" if key if key[/@$/] "#{m}#{key}#{text}" else "#{m}#{key}:#{text}" end else "#{m}#{text}" end end
parse()
click to toggle source
# File lib/honyomi/query.rb, line 32 def parse kp = OPTIONS.flatten.join('|') parts = @src.scan(/(-)?(?:(#{kp}):)?(?:"(.+)"|(\S+))/) page_query = [] bookmark_query = [] parts.each do |minus, key, quoted_value, value| if quoted_value text = %Q|"#{quoted_value}"| else text = value end unless (key) begin @jump_page_no = Integer(text) page_query << make_query(minus, text, "page_no") bookmark_query << make_query(minus, text, "page.page_no") rescue ArgumentError page_query << make_query(minus, text) bookmark_query << make_query(minus, text) end else case key when 'book', 'b' @key['book'] << text page_query << make_query(minus, text, "book") bookmark_query << make_query(minus, text, "page.book") when 'title', 't' @key['title'] << text page_query << make_query(minus, text, "book.title:@") bookmark_query << make_query(minus, text, "page.book.title:@") when 'page', 'p' @key['page'] << text page_query << make_query(minus, text, "page_no") bookmark_query << make_query(minus, text, "page.book.page_no") end end end @page_query = page_query.join(" ") @bookmark_query = bookmark_query.join(" ") end