Class: PolishGeeks::DevTools::Commands::EmptyMethods::FileParser

Inherits:
Object
  • Object
show all
Defined in:
lib/polish_geeks/dev_tools/commands/empty_methods/file_parser.rb

Overview

Parse file and search whether it contain empty methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileParser

Returns a new instance of FileParser.



10
11
12
13
# File 'lib/polish_geeks/dev_tools/commands/empty_methods/file_parser.rb', line 10

def initialize(file)
  @file = IO.readlines(file)
  @empty_methods = []
end

Instance Attribute Details

#empty_methodsObject (readonly)

Returns the value of attribute empty_methods.



7
8
9
# File 'lib/polish_geeks/dev_tools/commands/empty_methods/file_parser.rb', line 7

def empty_methods
  @empty_methods
end

Instance Method Details

#find_empty_methodsArray<Fixnum>

Returns list of lines where empty methods are defined.

Examples:

file = " class Example
  def empty_method; end
end
"
FileParser.new(file).find_empty_methods => [2]

file = ""
FileParser.new(file).find_empty_methods => []

Returns:

  • (Array<Fixnum>)

    list of lines where empty methods are defined



25
26
27
28
29
30
31
# File 'lib/polish_geeks/dev_tools/commands/empty_methods/file_parser.rb', line 25

def find_empty_methods
  @file.each_with_index do |line, index|
    next add_empty_method(index) if line.one_line_empty_method?
    check_bodies_existence(line, index)
  end
  empty_methods
end