Kenji Okimoto
null+****@clear*****
Fri Apr 28 16:31:17 JST 2017
Kenji Okimoto 2017-04-28 16:31:17 +0900 (Fri, 28 Apr 2017) New Revision: 02685f1034b85c17daea3c61b84d81e258bb1926 https://github.com/ranguba/chupa-text/commit/02685f1034b85c17daea3c61b84d81e258bb1926 Merged 0d7d7e0: Merge pull request #3 from okkez/add-plain-text-formatter Message: Add plain text formatter Added files: lib/chupa-text/formatters/text.rb Modified files: lib/chupa-text/command/chupa-text.rb lib/chupa-text/formatters.rb Modified: lib/chupa-text/command/chupa-text.rb (+14 -1) =================================================================== --- lib/chupa-text/command/chupa-text.rb 2017-03-01 23:48:59 +0900 (cccbf37) +++ lib/chupa-text/command/chupa-text.rb 2017-04-28 16:31:17 +0900 (9603f7e) @@ -26,10 +26,13 @@ module ChupaText end end + AVAILABLE_FORMATS = [:json, :text] + def initialize @input = nil @configuration = Configuration.default @enable_gems = true + @format = :json end def run(*arguments) @@ -89,6 +92,11 @@ module ChupaText "Appends PATH to decomposer load path.") do |path| $LOAD_PATH << path end + parser.on("--format=FORMAT", "Output FORMAT (#{AVAILABLE_FORMATS.join(',')})") do |format| + format = format.to_sym + raise ArgumentError, "Unknown format: #{format}" unless AVAILABLE_FORMATS.include?(format) + @format = format + end parser.separator("") parser.separator("Log related options:") @@ -150,7 +158,12 @@ module ChupaText end def create_formatter - Formatters::JSON.new($stdout) + case @format + when :json + Formatters::JSON.new($stdout) + when :text + Formatters::Text.new($stdout) + end end end end Modified: lib/chupa-text/formatters.rb (+1 -0) =================================================================== --- lib/chupa-text/formatters.rb 2017-03-01 23:48:59 +0900 (a5b80bf) +++ lib/chupa-text/formatters.rb 2017-04-28 16:31:17 +0900 (dd1bd19) @@ -15,3 +15,4 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA require "chupa-text/formatters/json" +require "chupa-text/formatters/text" Added: lib/chupa-text/formatters/text.rb (+22 -0) 100644 =================================================================== --- /dev/null +++ lib/chupa-text/formatters/text.rb 2017-04-28 16:31:17 +0900 (a9b8cca) @@ -0,0 +1,22 @@ +module ChupaText + module Formatters + class Text + def initialize(output) + @output = output + @texts = [] + end + + def format_start(data) + end + + def format_extracted(data) + @texts << data.body + end + + def format_finish(data) + @output << @texts.join("\n\x0c\n") + @output << "\n" + end + end + end +end -------------- next part -------------- HTML����������������������������...Download