script/knows.rb in boty-0.0.12 vs script/knows.rb in boty-0.0.13
- old
+ new
@@ -1,10 +1,30 @@
-desc I18n.t "scripts.knows"
+desc "knows", I18n.t("scripts.knows")
respond(/knows/i) do
- message = know_how.inject("") { |_message, command|
+ say KnownFormmater.new(know_how).format
+end
- _message << command.first
- _message << ": #{command.last}" if command.last
- _message << "\n"
- }
- say message
+class KnownFormmater
+ def initialize(actions)
+ @actions = actions
+ @max_size = @actions.keys.map(&:length).max
+ end
+
+ def format
+ @actions.inject("```\n") { |_message, command|
+ _message << format_command(command) + "\n"
+ } + "```"
+ end
+
+ private
+
+ def name(command_name)
+ pad = @max_size - command_name.length
+ (" " * pad) + command_name
+ end
+
+ def format_command(command)
+ message = name command.first
+ message << ": #{command.last}" if command.last
+ message
+ end
end