Class: Svnlog2csv::Row
- Inherits:
-
Object
- Object
- Svnlog2csv::Row
- 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
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#day ⇒ Object
readonly
Returns the value of attribute day.
Class Method Summary collapse
-
.legend(authors) ⇒ Object
Metodo statico che produce un array pronto per essere scritto sul csv.
Instance Method Summary collapse
-
#add(log_entry) ⇒ Object
Aggiunge i dati di un commit alla riga.
-
#initialize(day, authors) ⇒ Row
constructor
A new instance of Row.
-
#to_csv ⇒ Object
Produce un array pronto per essere scritto sul csv.
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, @day = day = .map { || .to_sym } @actions = Hash.new .each { || @actions[] = Hash.new(0) } end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
11 12 13 |
# File 'lib/svnlog2csv/row.rb', line 11 def actions @actions end |
#day ⇒ Object (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 arr = .map do || = .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| = log_entry..to_sym @actions[][action] += value @actions[][:tot] += value end end |
#to_csv ⇒ Object
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 = .map do || = .to_sym [@actions[][:A], @actions[][:M], @actions[][:D], @actions[][:tot]] end [@day] + arr.flatten end |