Class: Humr::Runner
- Inherits:
-
Object
- Object
- Humr::Runner
- Defined in:
- lib/humr/runner.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #colorize(chunk, handler) ⇒ Object
- #handlers ⇒ Object
-
#initialize(args) ⇒ Runner
constructor
A new instance of Runner.
- #readable_field(field) ⇒ Object
- #readable_line(line) ⇒ Object
- #run ⇒ Object
- #splitter ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/humr/runner.rb', line 12 def config @config end |
Class Method Details
.bootstrap(args) ⇒ Object
19 20 21 |
# File 'lib/humr/runner.rb', line 19 def self.bootstrap(args) new(args).run end |
Instance Method Details
#colorize(chunk, handler) ⇒ Object
63 64 65 |
# File 'lib/humr/runner.rb', line 63 def colorize(chunk, handler) Term::ANSIColor.send(config.color(handler), chunk) end |
#handlers ⇒ Object
27 28 29 30 31 |
# File 'lib/humr/runner.rb', line 27 def handlers @handlers ||= config.handlers.map do |name| Handler[name].new end end |
#readable_field(field) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# 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) ⇒ Object
46 47 48 49 50 |
# File 'lib/humr/runner.rb', line 46 def readable_line(line) splitter.sub_each_field(line) do |field| readable_field field end end |
#run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |