Class: SlimKeyfy::Console::Printer
- Defined in:
- lib/slimkeyfy/console/printer.rb
Class Method Summary collapse
- .difference(old_line, new_line, translations) ⇒ Object
- .indentation(line) ⇒ Object
- .normalize(line) ⇒ Object
- .tag(old_line, translations, comment_tag) ⇒ Object
- .unix_diff(bak_path, file_path) ⇒ Object
Class Method Details
.difference(old_line, new_line, translations) ⇒ Object
2 3 4 5 6 |
# File 'lib/slimkeyfy/console/printer.rb', line 2 def self.difference(old_line, new_line, translations) puts "#{'-'.red} #{normalize(old_line).red}" puts "#{'+'.green} #{normalize(new_line).green} => #{translations.to_s.yellow}" puts "-"*40 end |
.indentation(line) ⇒ Object
28 29 30 31 |
# File 'lib/slimkeyfy/console/printer.rb', line 28 def self.indentation(line) return "" if line.nil? or line.empty? " " * (line.size - line.gsub(/^\s+/, "").size) end |
.normalize(line) ⇒ Object
21 22 23 |
# File 'lib/slimkeyfy/console/printer.rb', line 21 def self.normalize(line) line.sub(/^\s*/, " ") end |
.tag(old_line, translations, comment_tag) ⇒ Object
24 25 26 27 |
# File 'lib/slimkeyfy/console/printer.rb', line 24 def self.tag(old_line, translations, comment_tag) prettified_translations = translations.map{|k, v| "#{k}: #{v}, t('.#{k.split(".").last}')" }.join(" | ") "#{indentation(old_line)}#{comment_tag} #{prettified_translations}\n#{old_line}" end |
.unix_diff(bak_path, file_path) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/slimkeyfy/console/printer.rb', line 7 def self.unix_diff(bak_path, file_path) result = "Please install colordiff or diff (brew install colordiff)" colordiff, diff = `which colordiff`, `which diff` if not colordiff.empty? result = `colordiff #{bak_path} #{file_path}` elsif not diff.empty? result =`diff #{bak_path} #{file_path}` end if result.nil? or result.strip.empty? puts "No changes for comparison found!" else puts "#{result}" end end |