-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctag.rb
61 lines (50 loc) · 1.13 KB
/
ctag.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Ctag
KIND_UNKNOWN = 'unknown'
KIND_CLASS = 'class'
KIND_FUNCTION = 'function'
KIND_METHOD = 'method'
KIND_VAR = 'variable'
attr_reader :tag, :file, :ex_cmd
attr_accessor :kind, :line, :lang, :klass
@@tags = nil
def initialize(tag, file, ex_cmd)
@tag = tag
@file = file
@ex_cmd = ex_cmd
@kind = Ctag::KIND_UNKNOWN
end
def self.tags=(tags)
@@tags = tags
end
def self.tags
@@tags
end
def self.find_all_by_class(klass)
find_all(:key => :klass, :value => klass)
end
def self.find_all_by_kind(kind)
find_all(:key => :kind, :value => kind)
end
def self.find_all_by_tag(tag)
find_all(:key => :tag, :value => tag)
end
def self.find_all_by_file(file)
find_all(:key => :file, :value => file)
end
def self.find_all(params)
@@tags.find_all do |tag|
case params[:key]
when :kind
tag.kind == params[:value]
when :tag
tag.tag == params[:value]
when :file
tag.file == params[:value]
when :klass
tag.klass == params[:value]
else
false
end
end
end
end