Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #3 from okkez/add-plain-text-formatter
Browse files Browse the repository at this point in the history
Add plain text formatter
  • Loading branch information
okkez committed Apr 28, 2017
2 parents 44f299d + 6b33af4 commit 0d7d7e0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/chupa-text/command/chupa-text.rb
Expand Up @@ -26,10 +26,13 @@ def run(*arguments)
end
end

AVAILABLE_FORMATS = [:json, :text]

def initialize
@input = nil
@configuration = Configuration.default
@enable_gems = true
@format = :json
end

def run(*arguments)
Expand Down Expand Up @@ -89,6 +92,13 @@ def create_option_parser
"Appends PATH to decomposer load path.") do |path|
$LOAD_PATH << path
end
parser.on("--format=FORMAT", AVAILABLE_FORMATS,
"Output FORMAT.",
"[#{AVAILABLE_FORMATS.join(', ')}]",
"(default: json)") do |format|
format = format.to_sym
@format = format
end

parser.separator("")
parser.separator("Log related options:")
Expand Down Expand Up @@ -150,7 +160,12 @@ def create_data
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
Expand Down
1 change: 1 addition & 0 deletions lib/chupa-text/formatters.rb
Expand Up @@ -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"
22 changes: 22 additions & 0 deletions lib/chupa-text/formatters/text.rb
@@ -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

0 comments on commit 0d7d7e0

Please sign in to comment.