Class: GitReporting::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/git_reporting.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_options) ⇒ Reporter

Returns a new instance of Reporter.



32
33
34
35
36
37
38
39
40
# File 'lib/git_reporting.rb', line 32

def initialize(source_options)
  @source = case source_options
  when Source then source_options
  when Array then Source::Array.new(source_options)
  when Hash then Source.from_options(source_options)
  else
    raise ArgumentError, "You should initialize GitReporting::Reporter with array, hash of source options or GitReporting::Source instance."
  end
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



30
31
32
# File 'lib/git_reporting.rb', line 30

def source
  @source
end

Instance Method Details

#build_report(options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/git_reporting.rb', line 42

def build_report(options = {})
  type = options[:type] || :simple
  group = options[:group] || :none
  from_time = options[:from].present? ? parse_time(options[:from]) : Time.at(0)
  to_time = options[:to].present? ? parse_time(options[:to]) : Time.current

  commits = source.fetch(from_time..to_time)

  root = Report.new("Report")
  root << Report::Group.const_get(group.to_s.capitalize).build(commits) do |group_commits|
    Report::Type.const_get(type.to_s.capitalize).build(group_commits)
  end
end