Class: Giteaucrat::Formatters::RubyFormatter
- Inherits:
-
Formatter
- Object
- SimpleDelegator
- Formatter
- Giteaucrat::Formatters::RubyFormatter
show all
- Defined in:
- lib/giteaucrat/formatters/ruby_formatter.rb
Constant Summary
collapse
%w[# # #].freeze
- CODING_REGEXP =
/\A((#\s*.*coding:\s*[^\s]+)\s*\n+)?/
- COPYRIGHT_REGEXP =
/(?<ruler>##+#\n)(?<copyright>(#\s*[^\s#]+.*\s#\n)+)(#\s+#?\n(?<comment>(#\s*.*#?\n)+))?\k<ruler>\n+/
Constants inherited
from Formatter
Formatter::HASHBANG_REGEXP
Instance Attribute Summary
Attributes inherited from Formatter
#comment_lines
Instance Method Summary
collapse
Methods inherited from Formatter
#add_copyright!, #comment?, #comment_parts, #footer_ruler, #header_ruler, #ruler, #write_copyright!
Instance Method Details
#encoding ⇒ Object
49
50
51
|
# File 'lib/giteaucrat/formatters/ruby_formatter.rb', line 49
def encoding
@encoding || (include_encoding? && '# coding: utf-8' || nil)
end
|
20
21
22
23
24
|
# File 'lib/giteaucrat/formatters/ruby_formatter.rb', line 20
def format_copyright
copyright = super
copyright = [encoding, copyright].compact.join("\n\n")
copyright
end
|
26
27
28
29
|
# File 'lib/giteaucrat/formatters/ruby_formatter.rb', line 26
def format_line(line)
first, _, last =
"#{first} #{line} #{last}"
end
|
#include_encoding? ⇒ Boolean
45
46
47
|
# File 'lib/giteaucrat/formatters/ruby_formatter.rb', line 45
def include_encoding?
repo.include_encoding?
end
|
37
38
39
40
41
42
43
|
# File 'lib/giteaucrat/formatters/ruby_formatter.rb', line 37
def ()
middle = Regexp.escape([1])
= .split("\n").map do |line|
line.sub(/\A#{middle}\s?/, '').sub(/\s*#{middle}\s*\Z/, '')
end
@comment_lines =
end
|
#remove_copyright! ⇒ Object
31
32
33
34
35
|
# File 'lib/giteaucrat/formatters/ruby_formatter.rb', line 31
def remove_copyright!
super
contents.sub!(CODING_REGEXP, '')
@encoding = Regexp.last_match(2) if Regexp.last_match(2)
end
|