Class: MetricFu::SexpNode
- Inherits:
-
Struct
- Object
- Struct
- MetricFu::SexpNode
show all
- Defined in:
- lib/metric_fu/data_structures/sexp_node.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#sexp ⇒ Object
Returns the value of attribute sexp
3
4
5
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 3
def sexp
@sexp
end
|
Class Method Details
.parse(contents) ⇒ Object
5
6
7
8
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 5
def self.parse(contents)
rp = RubyParser.new
rp.parse(contents)
end
|
Instance Method Details
#class_method_separator ⇒ Object
80
81
82
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 80
def class_method_separator
"::"
end
|
#each_class(&block) ⇒ Object
31
32
33
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 31
def each_class(&block)
each_of_type(:class, &block)
end
|
#each_class_method(&block) ⇒ Object
43
44
45
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 43
def each_class_method(&block)
each_of_type(:defs, ClassMethodNode, &block)
end
|
#each_instance_method(&block) ⇒ Object
39
40
41
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 39
def each_instance_method(&block)
each_of_type(:defn, InstanceMethodNode, &block)
end
|
#each_module(&block) ⇒ Object
27
28
29
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 27
def each_module(&block)
each_of_type(:module, &block)
end
|
#each_of_type(type, node_class = SexpNode) ⇒ Object
21
22
23
24
25
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 21
def each_of_type(type, node_class = SexpNode)
sexp.each_of_type(type) do |child_sexp|
yield node_class.new(child_sexp)
end
end
|
#each_singleton_class(&block) ⇒ Object
35
36
37
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 35
def each_singleton_class(&block)
each_of_type(:sclass, SingletonMethodNode, &block)
end
|
#first_line ⇒ Object
47
48
49
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 47
def first_line
sexp.line
end
|
#full_method_name(method_separator, class_name, module_name = nil) ⇒ Object
64
65
66
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 64
def full_method_name(method_separator, class_name, module_name = nil)
[module_namespace(module_name), class_name, method_separator, name].join
end
|
#hide_methods_from_next_round ⇒ Object
59
60
61
62
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 59
def hide_methods_from_next_round
sexp.find_and_replace_all(:defn, :ignore_me)
sexp.find_and_replace_all(:defs, :ignore_me)
end
|
#instance_method_separator ⇒ Object
76
77
78
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 76
def instance_method_separator
"#"
end
|
#last_line ⇒ Object
51
52
53
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 51
def last_line
sexp.last.line
end
|
#line_range ⇒ Object
55
56
57
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 55
def line_range
(first_line..last_line)
end
|
#module_namespace(module_name = nil) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 68
def module_namespace(module_name = nil)
if module_name.nil?
nil
else
[module_name, class_method_separator].join
end
end
|
#name ⇒ Object
17
18
19
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 17
def name
sexp[1]
end
|
#nil? ⇒ Boolean
9
10
11
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 9
def nil?
sexp.nil?
end
|
#node_type ⇒ Object
13
14
15
|
# File 'lib/metric_fu/data_structures/sexp_node.rb', line 13
def node_type
sexp[0]
end
|