Class: Codetree::ParseTree
- Inherits:
-
Object
- Object
- Codetree::ParseTree
- Defined in:
- lib/codetree.rb
Constant Summary collapse
- NESTING_NODES =
[:module, :class ]
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#operators ⇒ Object
readonly
Returns the value of attribute operators.
Instance Method Summary collapse
- #format_operator(name, _options = {:detail => :full}) ⇒ Object
-
#initialize(files) ⇒ ParseTree
constructor
A new instance of ParseTree.
- #print_tree(_options = { :detail => :medium, :flat => false, :quiet => false}) ⇒ Object
Constructor Details
#initialize(files) ⇒ ParseTree
Returns a new instance of ParseTree.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/codetree.rb', line 55 def initialize(files) @lines = Array::new files.each do |file| require "./#{file}" @lines << File::readlines(file) end @lines.flatten! @lines = @lines.collect(&:strip!) @lines.delete_if {|line| line =~ /^\s*#/} @code = @lines.join("\n") @ast = RubyParser.new.process @code, "code" @operators = {} # positions of interest @operators_index = Hash::new @curr_position = [] map_operators! generate_tree! end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
52 53 54 |
# File 'lib/codetree.rb', line 52 def ast @ast end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
53 54 55 |
# File 'lib/codetree.rb', line 53 def lines @lines end |
#operators ⇒ Object (readonly)
Returns the value of attribute operators.
51 52 53 |
# File 'lib/codetree.rb', line 51 def operators @operators end |
Instance Method Details
#format_operator(name, _options = {:detail => :full}) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/codetree.rb', line 76 def format_operator(name, = {:detail => :full}) res = "" [:detail] ||= :full scope = { :private => { :full => "Private ", :medium => '-', :light => ''}, :public => { :full => "Public ", :medium => "+", :light => ''}, :protected => { :full => "Protected ", :medium => "#", :light => ''}, :none => { :full => "", :medium => " ", :light => ''} } type = { :defn => { :full => "Instance method ", :medium => '(m):', :light => ''}, :defs => { :full => "Class method ", :medium => "(m) ", :light => ''}, :class => { :full => "Class ", :medium => "(C) ", :light => ''}, :module => { :full => "Module ", :medium => "(M) ", :light => ''} } if @operators.include?(name) then operator = @operators[name] operator.ancestors.each do |ancestor| res += @operators[ancestor].render end res = scope[operator.scope][[:detail]] + type[operator.type][[:detail]] + res + operator.render end return res end |
#print_tree(_options = { :detail => :medium, :flat => false, :quiet => false}) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/codetree.rb', line 100 def print_tree( = { :detail => :medium, :flat => false, :quiet => false}) [:detail] ||= :medium [:flat] ||= false [:quiet] ||= false print_subtree(@root,0, ) end |