Class: Obst::PackLog::Record

Inherits:
Struct
  • Object
show all
Defined in:
lib/obst/pack_log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_changesObject

Returns the value of attribute file_changes

Returns:

  • (Object)

    the current value of file_changes



31
32
33
# File 'lib/obst/pack_log.rb', line 31

def file_changes
  @file_changes
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



31
32
33
# File 'lib/obst/pack_log.rb', line 31

def time
  @time
end

Instance Method Details

#date_wdayObject



32
33
34
# File 'lib/obst/pack_log.rb', line 32

def date_wday
  Time.parse(time).strftime('%F %a')
end

#group_by_final_statusObject



50
51
52
53
54
# File 'lib/obst/pack_log.rb', line 50

def group_by_final_status
  groups = Hash.new{ |h, k| h[k] = [] }
  file_changes.each_pair{ |file, changes| groups[changes.final] << file }
  groups
end

#group_inlines(&block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/obst/pack_log.rb', line 56

def group_inlines(&block)
  gbfs = group_by_final_status

  [
    [:new, :a, '#2db7b5'],
    [:mod, :m, '#d3be03'],
    [:del, :d, '#c71585'],
    [:nil, nil, 'grey']
  ].each do |long, short, color|
    files = gbfs[short]
    next if files.empty?
    inline_str = files.sort!.map{ |name| "[[#{name}]]" }.join(' / ')
    block.call("<font color='#{color}'>#{long} #{files.count}:</font> #{inline_str}")
  end
end

#incrementObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/obst/pack_log.rb', line 36

def increment
  file_changes.each_value.reduce(0) do |sum, changes|
    sum +=
      case changes.final
      when :a
        1
      when :d
        -1
      else
        0
      end
  end
end