class Sloc::Runner
Public Class Methods
new(options = {})
click to toggle source
# File lib/sloc/runner.rb, line 5 def initialize(options = {}) @options = options @analyzer = Analyzer.new(@options) end
Public Instance Methods
raw_report(paths)
click to toggle source
# File lib/sloc/runner.rb, line 19 def raw_report(paths) target_files = find_target_files(paths) # TODO: count sloc report = target_files.each_with_object({}) do |path, h| code = File.read(path) extension = File.extname(path) h[path] = @analyzer.analyze(code, extension) end process_options(report) end
report(paths)
click to toggle source
# File lib/sloc/runner.rb, line 14 def report(paths) require 'pp' PP.pp(raw_report(paths), '') end
run(paths)
click to toggle source
# File lib/sloc/runner.rb, line 10 def run(paths) report(paths) end
Private Instance Methods
desc?()
click to toggle source
# File lib/sloc/runner.rb, line 52 def desc? @options[:desc] end
find_target_files(paths)
click to toggle source
# File lib/sloc/runner.rb, line 64 def find_target_files(paths) files = paths.uniq.flat_map do |path| if File.directory?(path) Dir.glob("#{path}/**/*").select { |f| File.file?(f) } else File.exist?(path) ? path : nil end end files.compact.map { |f| File.expand_path(f) }.uniq end
limit?()
click to toggle source
# File lib/sloc/runner.rb, line 56 def limit? !limitation.nil? end
limitation()
click to toggle source
# File lib/sloc/runner.rb, line 60 def limitation @options[:limit] ? [@options[:limit].to_i, 0].max : nil end
order()
click to toggle source
# File lib/sloc/runner.rb, line 47 def order key = @options[:order] ? @options[:order].to_sym : nil Analyzer::REPORT_KEYS.include?(key) ? key : Analyzer::REPORT_KEYS.first end
process_options(report)
click to toggle source
# File lib/sloc/runner.rb, line 35 def process_options(report) r = report .sort_by { |_key, value| value[order] } # --order= .tap { |hash| hash.reverse! if desc? } # --desc if limit? Hash[r.first(limitation)] else Hash[r] end end