Class: LibyearBundler::Report

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

Overview

Responsible presenting data from the ‘::LibyearBundler::Models`. Should only be concerned with presentation, nothing else.

Constant Summary collapse

FMT_LIBYEARS_COLUMN =
"%10.1f".freeze
FMT_RELEASES_COLUMN =
"%10d".freeze
FMT_VERSIONS_COLUMN =
"%15s".freeze
FMT_SUMMARY_COLUMNS =
"%30s%15s%15s%15s%15s".freeze

Instance Method Summary collapse

Constructor Details

#initialize(gems, ruby, options, io) ⇒ Report

‘gems` - Array of `::LibyearBundler::Models::Gem` instances `options` - Instance of `::LibyearBundler::Options`



12
13
14
15
16
17
# File 'lib/libyear_bundler/report.rb', line 12

def initialize(gems, ruby, options, io)
  @gems = gems
  @ruby = ruby
  @options = options
  @io = io
end

Instance Method Details

#to_hObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/libyear_bundler/report.rb', line 31

def to_h
  @_to_h ||=
    begin
      summary = {
        gems: @gems,
        sum_libyears: 0.0
      }
      @gems.each { |gem| increment_metrics_summary(gem, summary) }

      begin
        increment_metrics_summary(@ruby, summary) if @ruby.outdated?
      rescue StandardError => e
        warn "Unable to calculate libyears for ruby itself: #{e}"
      end

      summary
    end
end

#writeObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/libyear_bundler/report.rb', line 19

def write
  to_h[:gems].each { |gem| put_line_summary(gem) }

  begin
    put_line_summary(@ruby) if @ruby.outdated?
  rescue StandardError => e
    warn "Unable to calculate libyears for ruby itself: #{e} (line summary)"
  end

  put_summary(to_h)
end