Class: RuboCop::Cop::PercentLiteralCorrector
- Inherits:
-
Object
- Object
- RuboCop::Cop::PercentLiteralCorrector
- Includes:
- Util
- Defined in:
- lib/rubocop/cop/correctors/percent_literal_corrector.rb
Overview
This autocorrects percent literals
Constant Summary
Constants included from Util
Constants included from PathUtil
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#preferred_delimiters ⇒ Object
readonly
Returns the value of attribute preferred_delimiters.
Instance Method Summary collapse
- #correct(corrector, node, char) ⇒ Object
-
#initialize(config, preferred_delimiters) ⇒ PercentLiteralCorrector
constructor
A new instance of PercentLiteralCorrector.
Methods included from Util
add_parentheses, any_descendant?, args_begin, args_end, begins_its_line?, comment_line?, comment_lines?, double_quotes_required?, escape_string, first_part_of_call_chain, indent, interpret_string_escapes, line, line_range, needs_escaping?, on_node, parentheses?, same_line?, to_string_literal, to_supported_styles, trim_string_interpolation_escape_character
Methods included from PathUtil
absolute?, glob?, hidden_dir?, hidden_file?, hidden_file_in_not_hidden_dir?, match_path?, maybe_hidden_file?, relative_path, smart_path
Constructor Details
#initialize(config, preferred_delimiters) ⇒ PercentLiteralCorrector
Returns a new instance of PercentLiteralCorrector.
11 12 13 14 |
# File 'lib/rubocop/cop/correctors/percent_literal_corrector.rb', line 11 def initialize(config, preferred_delimiters) @config = config @preferred_delimiters = preferred_delimiters end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/rubocop/cop/correctors/percent_literal_corrector.rb', line 9 def config @config end |
#preferred_delimiters ⇒ Object (readonly)
Returns the value of attribute preferred_delimiters.
9 10 11 |
# File 'lib/rubocop/cop/correctors/percent_literal_corrector.rb', line 9 def preferred_delimiters @preferred_delimiters end |
Instance Method Details
#correct(corrector, node, char) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/rubocop/cop/correctors/percent_literal_corrector.rb', line 16 def correct(corrector, node, char) escape = escape_words?(node) char = char.upcase if escape delimiters = delimiters_for("%#{char}") contents = new_contents(node, escape, delimiters) wrap_contents(corrector, node, contents, char, delimiters) end |