Navigation Menu

Skip to content

Commit

Permalink
Add plain text formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
okkez committed Apr 28, 2017
1 parent 44f299d commit 02685f1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
15 changes: 14 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,11 @@ def create_option_parser
"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:")
Expand Down Expand Up @@ -150,7 +158,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 02685f1

Please sign in to comment.