class RuboCop::Cop::Utils::FormatString::FormatSequence
The syntax of a format sequence is as follows.
“‘ %[flags][.precision]type “`
A format sequence consists of a percent sign, followed by optional flags, width, and precision indicators, then terminated with a field type character.
For more complex formatting, Ruby supports a reference by name.
Attributes
Public Class Methods
Source
# File lib/rubocop/cop/utils/format_string.rb, line 50 def initialize(match) @source = match[0] @begin_pos = match.begin(0) @end_pos = match.end(0) @flags = match[:flags].to_s + match[:more_flags].to_s @width = match[:width] @precision = match[:precision] @name = match[:name] @type = match[:type] @arg_number = match[:arg_number] end
Public Instance Methods
Source
# File lib/rubocop/cop/utils/format_string.rb, line 66 def annotated? name && @source.include?('<') end
Source
# File lib/rubocop/cop/utils/format_string.rb, line 75 def arity @source.scan('*').count + 1 end
Number of arguments required for the format sequence
Source
# File lib/rubocop/cop/utils/format_string.rb, line 79 def max_digit_dollar_num @source.scan(DIGIT_DOLLAR).map { |(digit_dollar_num)| digit_dollar_num.to_i }.max end
Source
# File lib/rubocop/cop/utils/format_string.rb, line 62 def percent? type == '%' end
Source
# File lib/rubocop/cop/utils/format_string.rb, line 83 def style if annotated? :annotated elsif template? :template else :unannotated end end
Source
# File lib/rubocop/cop/utils/format_string.rb, line 70 def template? name && @source.include?('{') end