class Humr::Runner
Attributes
config[R]
Public Class Methods
bootstrap(args)
click to toggle source
# File lib/humr/runner.rb, line 19 def self.bootstrap(args) new(args).run end
new(args)
click to toggle source
# File lib/humr/runner.rb, line 14 def initialize(args) @args = args @config = Config.new end
Public Instance Methods
colorize(chunk, handler)
click to toggle source
# File lib/humr/runner.rb, line 63 def colorize(chunk, handler) Term::ANSIColor.send(config.color(handler), chunk) end
handlers()
click to toggle source
# File lib/humr/runner.rb, line 27 def handlers @handlers ||= config.handlers.map do |name| Handler[name].new end end
readable_field(field)
click to toggle source
# File lib/humr/runner.rb, line 52 def readable_field(field) handlers.each do |handler| readable = handler.replace(field) do |chunk| colorize(chunk, handler.name) end return readable if readable end field end
readable_line(line)
click to toggle source
# File lib/humr/runner.rb, line 46 def readable_line(line) splitter.sub_each_field(line) do |field| readable_field field end end
run()
click to toggle source
# File lib/humr/runner.rb, line 33 def run OptionParser.new do |opts| opts.on('-s', '--splitter SPLITTER[:ARGS]', 'Specify ield splitter (default, pattern:re, ltsv)') do |splitter| impl, *args = splitter.split(/:/, 2) @splitter = Splitter::Impl[impl.to_sym].new(*args) end end.parse!(@args) STDIN.each_line do |line| puts readable_line(line.chomp) end end
splitter()
click to toggle source
# File lib/humr/runner.rb, line 23 def splitter @splitter ||= Splitter::Default.new end