Class: Writeexcel::Worksheet::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/writeexcel/comments.rb

Direct Known Subclasses

Comments

Instance Method Summary collapse

Constructor Details

#initializeCollection

Returns a new instance of Collection.



7
8
9
10
# File 'lib/writeexcel/comments.rb', line 7

def initialize
  @items = {}
  @array = nil
end

Instance Method Details

#<<(item) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/writeexcel/comments.rb', line 12

def <<(item)
  if @items[item.row]
    @items[item.row][item.col] = item
  else
    @items[item.row] = { item.col => item }
  end
end

#arrayObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/writeexcel/comments.rb', line 20

def array
  return @array if @array

  @array = []
  @items.keys.sort.each do |row|
    @items[row].keys.sort.each do |col|
      @array << @items[row][col]
    end
  end
  @array
end