Class: RuboCop::Cop::PercentLiteralCorrector

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/rubocop/cop/correctors/percent_literal_corrector.rb

Overview

This auto-corrects percent literals

Constant Summary

Constants included from Util

Util::LITERAL_REGEX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

begins_its_line?, comment_line?, double_quotes_required?, escape_string, first_part_of_call_chain, interpret_string_escapes, line_range, needs_escaping?, on_node, parentheses?, same_line?, to_string_literal, to_supported_styles, tokens

Methods included from PathUtil

absolute?, hidden_dir?, hidden_file_in_not_hidden_dir?, match_path?, pwd, relative_path, reset_pwd, 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

#configObject (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_delimitersObject (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(node, char) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rubocop/cop/correctors/percent_literal_corrector.rb', line 16

def correct(node, char)
  escape = escape_words?(node)
  char = char.upcase if escape
  delimiters = delimiters_for("%#{char}")
  contents = new_contents(node, escape, delimiters)
  wrap_contents(node, contents, char, delimiters)
end