Class Row
In: lib/grid.rb
Parent: Array

Methods

[]   blank?   new   to_hash  

Public Class methods

[Source]

     # File lib/grid.rb, line 331
331:   def initialize(cells, grid)
332:     super(cells)
333:     @grid = grid
334:   end

Public Instance methods

second_arg for superclass methods

[Source]

     # File lib/grid.rb, line 337
337:   def [](index, second_arg = -1)
338:     return super if second_arg != -1
339:     if index.is_a?(String)
340:       index = @grid.index_for_column_name(index)
341:       return '' if index.blank?
342:     end
343: 
344:     return '' if index >= size
345:     return slice(index) || ''
346:   end

[Source]

     # File lib/grid.rb, line 388
388:   def blank?
389:     self.each do |cell|
390:       return false unless cell.blank?
391:     end
392:     true
393:   end

Concatenates duplicate keys into one value separated by a line return. Example: name | street | street Eddy | 10 Huy St | Apt 410

:name => ‘Eddy’ :steet => ‘10 Huy St

           Apt #410'

[Source]

     # File lib/grid.rb, line 356
356:   def to_hash
357:     hash = HashWithIndifferentAccess.new
358:     for index in 0..(size - 1)
359:       column = @grid.columns[index]
360:       field = column.field
361:       if field
362: 
363:         # Existing value logic is too messy ...
364:         value = self[index]
365:         if field == :notes and !value.blank? and value[/notes/].nil? and value[/Notes/].nil? and column.description[/notes/].nil? and column.description[/Notes/].nil?
366:           value = "#{column.description}: #{value}"
367:         end
368: 
369:         existing_value = hash[field]
370:         value = nil if value == $INPUT_RECORD_SEPARATOR
371:         if existing_value.blank?
372:           if value.blank?
373:             hash.delete(field)
374:           else
375:             hash[field] = value
376:           end
377:         else   
378:           unless value.blank?
379:             hash[field] = "#{existing_value}#{$INPUT_RECORD_SEPARATOR}#{value}"
380:           end
381:         end
382: 
383:       end
384:     end
385:     hash
386:   end

[Validate]