class WC::Printer
Public Class Methods
new(options)
click to toggle source
# File lib/wc/printer.rb, line 5 def initialize(options) @lines = options[:lines] @words = options[:words] @chars = options[:chars] @bytes = options[:bytes] @formatter = -> (limit) { "%#{limit}d%#{limit}d%#{limit}d" } end
Public Instance Methods
format(limit, stats)
click to toggle source
# File lib/wc/printer.rb, line 13 def format(limit, stats) @formatter[limit] % [stats[:lines], stats[:words], stats[:chars]] end
render(filename, stats, limit)
click to toggle source
# File lib/wc/printer.rb, line 17 def render(filename, stats, limit) output = "" if @lines output << "%#{limit}d" % stats[:lines].to_s elsif @words output << "%#{limit}d" % stats[:words].to_s elsif @chars output << "%#{limit}d" % stats[:chars].to_s elsif @bytes output << "%#{limit}d" % stats[:bytes].to_s else output << format(limit, stats) end puts output << " #{filename}" end