Class: AbcSize::Calculator
- Inherits:
-
Object
- Object
- AbcSize::Calculator
- Defined in:
- lib/abc_size/calculator.rb
Overview
main class
Constant Summary collapse
- SATISFACTORY_ABC_SIZE =
17
Instance Attribute Summary collapse
-
#discount ⇒ Object
readonly
Returns the value of attribute discount.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#ruby_version ⇒ Object
readonly
Returns the value of attribute ruby_version.
-
#source_code ⇒ Object
readonly
Returns the value of attribute source_code.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(source_code: nil, path: nil, parameters: nil) ⇒ Calculator
constructor
A new instance of Calculator.
Constructor Details
#initialize(source_code: nil, path: nil, parameters: nil) ⇒ Calculator
Returns a new instance of Calculator.
14 15 16 17 18 19 20 21 22 |
# File 'lib/abc_size/calculator.rb', line 14 def initialize(source_code: nil, path: nil, parameters: nil) @source_code = source_code @path = path @parameters = parameters @discount = @parameters.map { |parameter| ['-d', '--discount'].include?(parameter) }.any?(true) @results = [] end |
Instance Attribute Details
#discount ⇒ Object (readonly)
Returns the value of attribute discount.
12 13 14 |
# File 'lib/abc_size/calculator.rb', line 12 def discount @discount end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
12 13 14 |
# File 'lib/abc_size/calculator.rb', line 12 def parameters @parameters end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/abc_size/calculator.rb', line 12 def path @path end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
12 13 14 |
# File 'lib/abc_size/calculator.rb', line 12 def results @results end |
#ruby_version ⇒ Object (readonly)
Returns the value of attribute ruby_version.
12 13 14 |
# File 'lib/abc_size/calculator.rb', line 12 def ruby_version @ruby_version end |
#source_code ⇒ Object (readonly)
Returns the value of attribute source_code.
12 13 14 |
# File 'lib/abc_size/calculator.rb', line 12 def source_code @source_code end |
Instance Method Details
#call ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/abc_size/calculator.rb', line 24 def call source = source_code || read_source_code_from_file @ruby_version = return_ruby_version nodes = RuboCop::AST::ProcessedSource.new(source, ruby_version).ast nodes.each_node { |node| results << calculate_result(node) if node.is_a?(RuboCop::AST::DefNode) } # return results for testing purposes results end |