Class: Milkode::Query

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_stringObject (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_gotolineObject

‘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_packagesObject

‘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_fpathObject



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_packagesObject



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

Returns:

  • (Boolean)


36
37
38
# File 'lib/milkode/cdweb/lib/query.rb', line 36

def empty?
  keywords.size == 0 && only_keywords
end

#escape_htmlObject



32
33
34
# File 'lib/milkode/cdweb/lib/query.rb', line 32

def escape_html
  Rack::Utils::escape_html(@query_string)
end

#fpath_or_packagesObject



60
61
62
# File 'lib/milkode/cdweb/lib/query.rb', line 60

def fpath_or_packages
  calc_param(3)
end

#fpathsObject



52
53
54
# File 'lib/milkode/cdweb/lib/query.rb', line 52

def fpaths
  calc_param(1)
end

#gotolinesObject



69
70
71
# File 'lib/milkode/cdweb/lib/query.rb', line 69

def gotolines
  calc_param(5)
end

#keywordsObject



44
45
46
# File 'lib/milkode/cdweb/lib/query.rb', line 44

def keywords
  @hash['keywords']
end

#multi_match_keywordsObject



64
65
66
67
# File 'lib/milkode/cdweb/lib/query.rb', line 64

def multi_match_keywords
  # 本当はkeywordsにしたかった・・
  calc_param(4)
end

#only_keywordsObject



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

#packagesObject



48
49
50
# File 'lib/milkode/cdweb/lib/query.rb', line 48

def packages
  calc_param(0)
end

#suffixsObject



56
57
58
# File 'lib/milkode/cdweb/lib/query.rb', line 56

def suffixs
  calc_param(2)
end

#wide_match_rangeObject



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

Returns:

  • (Boolean)


89
90
91
# File 'lib/milkode/cdweb/lib/query.rb', line 89

def wide_match_range_empty?
  @wide_match_range.empty?
end