Class: Rubycritic::FileGenerator
Constant Summary
collapse
- LINE_NUMBER_OFFSET =
1
- TEMPLATE =
erb_template("file.html.erb")
BaseGenerator::LAYOUT_TEMPLATE, BaseGenerator::TEMPLATES_DIR
Instance Method Summary
collapse
erb_template, #file_href, #file_pathname, #get_binding
#analysed_file_name, #asset_path, #code_index_path, #javascript_path, #overview_path, #root_directory, #smell_location_path, #smells_index_path, #stylesheet_path
Constructor Details
#initialize(pathname, smells) ⇒ FileGenerator
11
12
13
14
|
# File 'lib/rubycritic/report_generators/file_generator.rb', line 11
def initialize(pathname, smells)
@pathname = pathname
@smells = smells
end
|
Instance Method Details
#file_directory ⇒ Object
16
17
18
|
# File 'lib/rubycritic/report_generators/file_generator.rb', line 16
def file_directory
File.join(root_directory, @pathname.dirname)
end
|
#file_has_smells? ⇒ Boolean
36
37
38
|
# File 'lib/rubycritic/report_generators/file_generator.rb', line 36
def file_has_smells?
!@smells.empty?
end
|
#file_name ⇒ Object
20
21
22
|
# File 'lib/rubycritic/report_generators/file_generator.rb', line 20
def file_name
@pathname.basename.sub_ext(".html")
end
|
#render ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/rubycritic/report_generators/file_generator.rb', line 24
def render
file_code = ""
File.readlines(@pathname).each.with_index(LINE_NUMBER_OFFSET) do |line_text, line_number|
location = Location.new(@pathname, line_number)
line_smells = @smells.select { |smell| smell.located_in?(location) }
file_code << LineGenerator.new(line_text, line_smells).render
end
file_body = TEMPLATE.result(get_binding { file_code })
LAYOUT_TEMPLATE.result(get_binding { file_body })
end
|