Class: Svnlog2csv::Row

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

Overview

Row corrisponde a una riga che andrà scritta sul file csv. Ogni row è caratterizzata da una data (day) e una serie di azioni (actions). actions è un hash di hash, la cui struttura è

@actions[autore][tipo_azione]

tipo_azione è uno fra A (add), M (modify), D (delete), tot (totale). tot è semplicemente la somma di A, M e D.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(day, authors) ⇒ Row

Returns a new instance of Row.



13
14
15
16
17
18
# File 'lib/svnlog2csv/row.rb', line 13

def initialize day, authors
  @day = day
  @authors = authors.map { |author| author.to_sym }
  @actions = Hash.new
  @authors.each { |author| @actions[author] = Hash.new(0) }
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



11
12
13
# File 'lib/svnlog2csv/row.rb', line 11

def actions
  @actions
end

#dayObject (readonly)

Returns the value of attribute day.



11
12
13
# File 'lib/svnlog2csv/row.rb', line 11

def day
  @day
end

Class Method Details

.legend(authors) ⇒ Object

Metodo statico che produce un array pronto per essere scritto sul csv. Contiene la legenda del csv.



47
48
49
50
51
52
53
# File 'lib/svnlog2csv/row.rb', line 47

def self.legend authors
  arr = authors.map do |author|
    author = author.to_sym
    ["#{author} A", "#{author} M", "#{author} D", "#{author} TOT"]
  end
  ["Data"] + arr.flatten
end

Instance Method Details

#add(log_entry) ⇒ Object

Aggiunge i dati di un commit alla riga. Se autore “pippo” ha fatto un commit con 2 add e 1 modify, viene eseguito l’equivalente di queste operazioni:

@actions[:pippo][:A] += 2
@actions[:pippo][:M] += 1
@actions[:pippo][:tot] += 3


26
27
28
29
30
31
32
# File 'lib/svnlog2csv/row.rb', line 26

def add log_entry
  log_entry.actions.each_pair do |action, value|
    author = log_entry.author.to_sym
    @actions[author][action] += value
    @actions[author][:tot] += value
  end
end

#to_csvObject

Produce un array pronto per essere scritto sul csv. Viene scritta la data nella prima colonna, e per ogni autore quattro colonne (add, modify, delete, totale)



37
38
39
40
41
42
43
# File 'lib/svnlog2csv/row.rb', line 37

def to_csv
  arr = @authors.map do |author|
    author = author.to_sym
    [@actions[author][:A], @actions[author][:M], @actions[author][:D], @actions[author][:tot]]
  end
  [@day] + arr.flatten
end