Class: Fukuzatsu::Summary
- Inherits:
-
Object
- Object
- Fukuzatsu::Summary
- Defined in:
- lib/fukuzatsu/summary.rb
Constant Summary collapse
- BRANCHES =
[ :if, :or_asgn, :and_sgn, :or, :and ]
Instance Attribute Summary collapse
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#edges ⇒ Object
Returns the value of attribute edges.
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
-
#exits ⇒ Object
Returns the value of attribute exits.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#source_file ⇒ Object
readonly
Returns the value of attribute source_file.
-
#summaries ⇒ Object
Returns the value of attribute summaries.
Class Method Summary collapse
Instance Method Summary collapse
- #average_complexity ⇒ Object
- #complexity ⇒ Object
- #container_name ⇒ Object
- #entity_name ⇒ Object
-
#initialize(source:, entity:, container:, source_file: nil, summaries: []) ⇒ Summary
constructor
A new instance of Summary.
- #is_class_or_module? ⇒ Boolean
- #raw_source ⇒ Object
Constructor Details
#initialize(source:, entity:, container:, source_file: nil, summaries: []) ⇒ Summary
Returns a new instance of Summary.
42 43 44 45 46 47 48 49 |
# File 'lib/fukuzatsu/summary.rb', line 42 def initialize(source:, entity:, container:, source_file:nil, summaries:[]) @source = source @entity = entity @container = container @source_file = source_file @summaries = summaries @edges, @nodes, @exits = [0, 1, 1] end |
Instance Attribute Details
#container ⇒ Object (readonly)
Returns the value of attribute container.
5 6 7 |
# File 'lib/fukuzatsu/summary.rb', line 5 def container @container end |
#edges ⇒ Object
Returns the value of attribute edges.
6 7 8 |
# File 'lib/fukuzatsu/summary.rb', line 6 def edges @edges end |
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
5 6 7 |
# File 'lib/fukuzatsu/summary.rb', line 5 def entity @entity end |
#exits ⇒ Object
Returns the value of attribute exits.
6 7 8 |
# File 'lib/fukuzatsu/summary.rb', line 6 def exits @exits end |
#nodes ⇒ Object
Returns the value of attribute nodes.
6 7 8 |
# File 'lib/fukuzatsu/summary.rb', line 6 def nodes @nodes end |
#source_file ⇒ Object (readonly)
Returns the value of attribute source_file.
5 6 7 |
# File 'lib/fukuzatsu/summary.rb', line 5 def source_file @source_file end |
#summaries ⇒ Object
Returns the value of attribute summaries.
6 7 8 |
# File 'lib/fukuzatsu/summary.rb', line 6 def summaries @summaries end |
Class Method Details
.from(content:, source_file: nil) ⇒ Object
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 |
# File 'lib/fukuzatsu/summary.rb', line 16 def self.from(content:, source_file:nil) parser = Analyst.for_source(content) containers = parser.top_level_entities.select{|e| e.respond_to? :all_methods} containers << containers.map(&:classes) containers.flatten!.reject!{ |container| container.all_methods.empty? } containers.map do |container| summary = Fukuzatsu::Summary.new( container: container, source: container.send(:source), entity: container, source_file: source_file ) summary.summaries = container.all_methods.map do |method| Fukuzatsu::Summary.new( container: container, source: method.send(:source), entity: method, source_file: source_file ) end summary end end |
Instance Method Details
#average_complexity ⇒ Object
71 72 73 74 |
# File 'lib/fukuzatsu/summary.rb', line 71 def average_complexity return 0 if self.summaries.blank? self.summaries.map(&:complexity).reduce(&:+) / self.summaries.count.to_f end |
#complexity ⇒ Object
51 52 53 54 55 56 |
# File 'lib/fukuzatsu/summary.rb', line 51 def complexity @complexity ||= begin traverse(self.entity.ast) self.edges - self.nodes + self.exits end end |
#container_name ⇒ Object
58 59 60 |
# File 'lib/fukuzatsu/summary.rb', line 58 def container_name self.container.full_name end |
#entity_name ⇒ Object
66 67 68 69 |
# File 'lib/fukuzatsu/summary.rb', line 66 def entity_name return "*" if is_class_or_module? self.entity.full_name.gsub(self.container.full_name, '') end |
#is_class_or_module? ⇒ Boolean
62 63 64 |
# File 'lib/fukuzatsu/summary.rb', line 62 def is_class_or_module? self.container == self.entity end |
#raw_source ⇒ Object
76 77 78 |
# File 'lib/fukuzatsu/summary.rb', line 76 def raw_source self.source_file && "\n#{File.open(self.source_file, "r").read}" || @source end |