Class Results::Row
In: lib/results/row.rb
Parent: Object

Used by ResultsFile. Intermediate Hash-like model between Excel row and Result.

Methods

[]   blank?   first   first?   last?   new   notes   place   same_time?   size   to_hash   to_s  

Attributes

column_indexes  [R] 
next  [RW] 
previous  [RW] 
result  [RW] 
spreadsheet_row  [R] 
usac_results_format  [R] 

Public Class methods

[Source]

    # File lib/results/row.rb, line 11
11:     def initialize(spreadsheet_row, column_indexes, usac_results_format)
12:       @spreadsheet_row = spreadsheet_row
13:       @column_indexes = column_indexes
14:       @usac_results_format = usac_results_format
15:     end

Public Instance methods

[Source]

    # File lib/results/row.rb, line 17
17:     def [](column_symbol)
18:       index = column_indexes[column_symbol]
19:       if index
20:         case spreadsheet_row[index]
21:         when Spreadsheet::Formula
22:           value = spreadsheet_row[index].value
23:         when Spreadsheet::Excel::Error
24:           value = nil
25:         else
26:           value = spreadsheet_row[index]
27:         end
28:         value.strip! if value.respond_to?(:strip!)
29:         value
30:       end
31:     end

[Source]

    # File lib/results/row.rb, line 39
39:     def blank?
40:       spreadsheet_row.all? { |cell| cell.to_s.blank? }
41:     end

[Source]

    # File lib/results/row.rb, line 43
43:     def first
44:       spreadsheet_row[0]
45:     end

[Source]

    # File lib/results/row.rb, line 47
47:     def first?
48:       spreadsheet_row.idx == 0
49:     end

[Source]

    # File lib/results/row.rb, line 51
51:     def last?
52:       spreadsheet_row == spreadsheet_row.worksheet.last_row
53:     end

[Source]

    # File lib/results/row.rb, line 80
80:     def notes
81:       if usac_results_format
82:         # We want to pick up the info in the first 5 columns: org, year, event #, date, discipline
83:         return "" if blank? || size < 5
84:         spreadsheet_row[0, 5].select { |cell| cell.present? }.join(", ")
85:       else  
86:         return "" if blank? || size < 2
87:         spreadsheet_row[1, size - 1].select { |cell| cell.present? }.join(", ")
88:       end
89:     end

[Source]

    # File lib/results/row.rb, line 59
59:     def place
60:       if column_indexes[:place]
61:         value = self[:place]
62:       else
63:         value = spreadsheet_row[0]
64:         value = spreadsheet_row[0].value if spreadsheet_row[0].is_a?(Spreadsheet::Formula)
65:         value.strip! if value.respond_to?(:strip!)
66:       end
67: 
68:       # Mainly to handle Dates and DateTimes in the place column
69:       value = nil unless value.respond_to?(:to_i)
70:       value
71:     end

[Source]

    # File lib/results/row.rb, line 73
73:     def same_time?
74:       if previous && self[:time].present?
75:         row_time = self[:time].try(:to_s)
76:         row_time && (row_time[/st/i] || row_time[/s\.t\./i])
77:       end
78:     end

[Source]

    # File lib/results/row.rb, line 55
55:     def size
56:       spreadsheet_row.size
57:     end

[Source]

    # File lib/results/row.rb, line 33
33:     def to_hash
34:       hash = Hash.new
35:       column_indexes.keys.each { |key| hash[key] = self[key] }
36:       hash
37:     end

[Source]

    # File lib/results/row.rb, line 91
91:     def to_s
92:       "#<Results::ResultsFile::Row #{spreadsheet_row.to_a.join(', ')} >"
93:     end

[Validate]