class HOC::Base

Code base abstraction

Public Class Methods

new(opts) click to toggle source

Ctor.

opts

Options

# File lib/hoc.rb, line 33
def initialize(opts)
  @dir = opts[:dir]
  @exclude = opts[:exclude] || []
  @author = opts[:author] || ''
  @format = opts[:format] || 'int'
  @since = opts[:since] || '2000-01-01'
  @before = opts[:before] || Time.now.strftime('%Y-%m-%d')
end

Public Instance Methods

report() click to toggle source

Generate report.

# File lib/hoc.rb, line 43
def report
  repo = nil
  if File.exist?(File.join(@dir, '.git'))
    repo = Git.new(@dir, @exclude, @author, @since, @before)
  elsif File.exist?(File.join(@dir, '.svn'))
    repo = Svn.new(@dir)
  else
    raise 'Only Git repositories supported now'
  end
  count = repo.hits.map(&:total).inject(:+)
  case @format
  when 'xml'
    "<hoc><total>#{count}</total></hoc>"
  when 'json'
    "{\"total\":#{count}}"
  when 'text'
    "Total Hits-of-Code: #{count}"
  when 'int'
    count
  else
    raise 'Only "text|xml|json|int" formats are supported now'
  end
end