Class: RuboCop::Cop::Utils::FormatString
- Inherits:
-
Object
- Object
- RuboCop::Cop::Utils::FormatString
- Defined in:
- lib/rubocop/cop/utils/format_string.rb
Overview
Parses Kernel#sprintf format strings.
Defined Under Namespace
Classes: FormatSequence
Constant Summary collapse
- DIGIT_DOLLAR =
/(\d+)\$/.freeze
- FLAG =
/[ #0+-]|#{DIGIT_DOLLAR}/.freeze
- NUMBER_ARG =
/\*#{DIGIT_DOLLAR}?/.freeze
- NUMBER =
/\d+|#{NUMBER_ARG}/.freeze
- WIDTH =
/(?<width>#{NUMBER})/.freeze
- PRECISION =
/\.(?<precision>#{NUMBER})/.freeze
- TYPE =
/(?<type>[bBdiouxXeEfgGaAcps])/.freeze
- NAME =
/<(?<name>\w+)>/.freeze
- TEMPLATE_NAME =
/\{(?<name>\w+)\}/.freeze
- SEQUENCE =
/ % (?<type>%) | % (?<flags>#{FLAG}*) (?: (?: #{WIDTH}? #{PRECISION}? #{NAME}? | #{WIDTH}? #{NAME} #{PRECISION}? | #{NAME} (?<more_flags>#{FLAG}*) #{WIDTH}? #{PRECISION}? ) #{TYPE} | #{WIDTH}? #{PRECISION}? #{TEMPLATE_NAME} ) /x.freeze
Instance Method Summary collapse
- #format_sequences ⇒ Object
-
#initialize(string) ⇒ FormatString
constructor
A new instance of FormatString.
- #max_digit_dollar_num ⇒ Object
- #named_interpolation? ⇒ Boolean
Constructor Details
#initialize(string) ⇒ FormatString
Returns a new instance of FormatString.
92 93 94 |
# File 'lib/rubocop/cop/utils/format_string.rb', line 92 def initialize(string) @source = string end |
Instance Method Details
#format_sequences ⇒ Object
96 97 98 |
# File 'lib/rubocop/cop/utils/format_string.rb', line 96 def format_sequences @format_sequences ||= parse end |
#max_digit_dollar_num ⇒ Object
104 105 106 |
# File 'lib/rubocop/cop/utils/format_string.rb', line 104 def max_digit_dollar_num format_sequences.map(&:max_digit_dollar_num).max end |
#named_interpolation? ⇒ Boolean
100 101 102 |
# File 'lib/rubocop/cop/utils/format_string.rb', line 100 def named_interpolation? format_sequences.any?(&:name) end |