lib/hammer_cli/output/formatters.rb in hammer_cli-0.0.18 vs lib/hammer_cli/output/formatters.rb in hammer_cli-0.1.0
- old
+ new
@@ -107,12 +107,50 @@
""
end
end
end
+ class KeyValueFormatter < FieldFormatter
+
+ def tags
+ [:screen, :flat]
+ end
+
+ def format(params)
+ if params.is_a? Hash
+ name = params[:name] || params["name"]
+ value = params[:value] || params["value"]
+ "#{name} => #{value}"
+ else
+ ""
+ end
+ end
+ end
+
+ class LongTextFormatter < FieldFormatter
+
+ INDENT = " "
+
+ def initialize(options = {})
+ @indent = options[:indent].nil? ? true : options[:indent]
+ end
+
+ def tags
+ [:screen]
+ end
+
+ def format(text)
+ text = text.to_s.indent_with(INDENT) if @indent
+ "\n#{text}"
+ end
+ end
+
HammerCLI::Output::Output.register_formatter(DateFormatter.new, :Date)
HammerCLI::Output::Output.register_formatter(ListFormatter.new, :List)
+ HammerCLI::Output::Output.register_formatter(KeyValueFormatter.new, :KeyValue)
+ HammerCLI::Output::Output.register_formatter(LongTextFormatter.new, :LongText)
end
end
+