Class: Milkode::Query
- Inherits:
-
Object
- Object
- Milkode::Query
- Defined in:
- lib/milkode/cdweb/lib/query.rb
Constant Summary collapse
- OPTIONS =
[ ['package' , 'p'], ['filepath' , 'fpath', 'f'], ['suffix' , 's'], ['fp'] , # fpath or package ['keyword' , 'k'], ['gotoline' , 'g'], ['wide' , 'w'], ]
Instance Attribute Summary collapse
-
#query_string ⇒ Object
readonly
Returns the value of attribute query_string.
Instance Method Summary collapse
-
#conv_fuzzy_gotoline ⇒ Object
‘cdstk.rb:11’ -> ‘g:cdstk.rb:11’.
-
#conv_head_keyword_to_fpath_or_packages ⇒ Object
‘name def test’ -> ‘fp:name def test’.
- #conv_keywords_to_fpath ⇒ Object
- #conv_keywords_to_fpath_or_packages ⇒ Object
- #conv_wide_match_range(match_range) ⇒ Object
- #empty? ⇒ Boolean
- #escape_html ⇒ Object
- #fpath_or_packages ⇒ Object
- #fpaths ⇒ Object
- #gotolines ⇒ Object
-
#initialize(str) ⇒ Query
constructor
A new instance of Query.
- #keywords ⇒ Object
- #multi_match_keywords ⇒ Object
- #only_keywords ⇒ Object
- #packages ⇒ Object
- #suffixs ⇒ Object
- #wide_match_range ⇒ Object
- #wide_match_range_empty? ⇒ Boolean
Constructor Details
#initialize(str) ⇒ Query
Returns a new instance of Query.
25 26 27 28 29 30 |
# File 'lib/milkode/cdweb/lib/query.rb', line 25 def initialize(str) @query_string = str init_hash parse @wide_match_range = calc_param(6) end |
Instance Attribute Details
#query_string ⇒ Object (readonly)
Returns the value of attribute query_string.
13 14 15 |
# File 'lib/milkode/cdweb/lib/query.rb', line 13 def query_string @query_string end |
Instance Method Details
#conv_fuzzy_gotoline ⇒ Object
‘cdstk.rb:11’ -> ‘g:cdstk.rb:11’
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/milkode/cdweb/lib/query.rb', line 131 def conv_fuzzy_gotoline s = query_string.split.map {|v| if keywords[0].include? v "g:#{v}" else v end }.join(' ') Query.new(s) end |
#conv_head_keyword_to_fpath_or_packages ⇒ Object
‘name def test’ -> ‘fp:name def test’
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/milkode/cdweb/lib/query.rb', line 118 def conv_head_keyword_to_fpath_or_packages s = query_string.split.map {|v| if keywords[0].include? v "fp:#{v}" else v end }.join(' ') Query.new(s) end |
#conv_keywords_to_fpath ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/milkode/cdweb/lib/query.rb', line 93 def conv_keywords_to_fpath s = query_string.split.map {|v| if keywords.include? v "f:#{v}" else v end }.join(' ') Query.new(s) end |
#conv_keywords_to_fpath_or_packages ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/milkode/cdweb/lib/query.rb', line 105 def conv_keywords_to_fpath_or_packages s = query_string.split.map {|v| if keywords.include? v "fp:#{v}" else v end }.join(' ') Query.new(s) end |
#conv_wide_match_range(match_range) ⇒ Object
143 144 145 |
# File 'lib/milkode/cdweb/lib/query.rb', line 143 def conv_wide_match_range(match_range) Query.new(query_string + " w:#{match_range}") end |
#empty? ⇒ Boolean
36 37 38 |
# File 'lib/milkode/cdweb/lib/query.rb', line 36 def empty? keywords.size == 0 && only_keywords end |
#escape_html ⇒ Object
32 33 34 |
# File 'lib/milkode/cdweb/lib/query.rb', line 32 def escape_html Rack::Utils::escape_html(@query_string) end |
#fpath_or_packages ⇒ Object
60 61 62 |
# File 'lib/milkode/cdweb/lib/query.rb', line 60 def fpath_or_packages calc_param(3) end |
#fpaths ⇒ Object
52 53 54 |
# File 'lib/milkode/cdweb/lib/query.rb', line 52 def fpaths calc_param(1) end |
#gotolines ⇒ Object
69 70 71 |
# File 'lib/milkode/cdweb/lib/query.rb', line 69 def gotolines calc_param(5) end |
#keywords ⇒ Object
44 45 46 |
# File 'lib/milkode/cdweb/lib/query.rb', line 44 def keywords @hash['keywords'] end |
#multi_match_keywords ⇒ Object
64 65 66 67 |
# File 'lib/milkode/cdweb/lib/query.rb', line 64 def multi_match_keywords # 本当はkeywordsにしたかった・・ calc_param(4) end |
#only_keywords ⇒ Object
40 41 42 |
# File 'lib/milkode/cdweb/lib/query.rb', line 40 def only_keywords packages.size == 0 && fpaths.size == 0 && suffixs.size == 0 && fpath_or_packages.size == 0 && gotolines.size == 0 && wide_match_range_empty? end |
#packages ⇒ Object
48 49 50 |
# File 'lib/milkode/cdweb/lib/query.rb', line 48 def packages calc_param(0) end |
#suffixs ⇒ Object
56 57 58 |
# File 'lib/milkode/cdweb/lib/query.rb', line 56 def suffixs calc_param(2) end |
#wide_match_range ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/milkode/cdweb/lib/query.rb', line 73 def wide_match_range a = @wide_match_range if a.empty? 1 else i = a[-1].to_i if (i == 0) 0 else i end end end |
#wide_match_range_empty? ⇒ Boolean
89 90 91 |
# File 'lib/milkode/cdweb/lib/query.rb', line 89 def wide_match_range_empty? @wide_match_range.empty? end |