module RuboCop::Yast::Reformatter
patch the Rubocop config - include the plugin defaults
Public Instance Methods
interpolate(format, args)
click to toggle source
converts YCP format string to Ruby interpolation @param [String] format YCP format string (e.g. “foo: %1”) @param [Array<String>] args argument list @return [String] String with Ruby interpolation
# File lib/rubocop/yast/reformatter.rb, line 13 def interpolate(format, args) single_to_double(format).gsub(/%./) do |match| case match when "%%" "%" when /%([1-9])/ pos = Regexp.last_match[1].to_i - 1 "\#{" + args[pos] + "}" if pos < args.size end end end
single_to_double(str)
click to toggle source
convert single quoted string to double quoted to allow using string interpolation
# File lib/rubocop/yast/reformatter.rb, line 27 def single_to_double(str) ret = str.dup return ret if str.start_with?("\"") # esacpe interpolation start (ignred in single quoted string) ret.gsub!("\#{", "\\\#{") # esacpe double quotes (not needed in single quoted string) ret.gsub!("\"", "\\\"") # replace the around quotes ret[0] = "\"" ret[-1] = "\"" ret end