Class: Demos::Spreadsheet::CSV

Inherits:
Hokusai::Block show all
Defined in:
ui/examples/spreadsheet/csv.rb

Instance Attribute Summary

Attributes inherited from Hokusai::Block

#node, #provides, #publisher

Instance Method Summary collapse

Methods inherited from Hokusai::Block

#children, #children?, compile, computed, computed!, #draw, #draw_with, #dump, #emit, #initialize, inject, inject!, #method_missing, mount, #on_resize, provide, provides, #render, style, styles_get, template, template_from_file, template_get, #update, use, uses

Constructor Details

This class inherits a constructor from Hokusai::Block

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hokusai::Block

Instance Method Details

#change_cell(rowi, celli) ⇒ Object



188
189
190
# File 'ui/examples/spreadsheet/csv.rb', line 188

def change_cell(rowi, celli)
  emit("modified")
end

#column_countObject



233
234
235
# File 'ui/examples/spreadsheet/csv.rb', line 233

def column_count
  csv.to_a.map(&:size).max
end

#empty_rowObject



229
230
231
# File 'ui/examples/spreadsheet/csv.rb', line 229

def empty_row
  Array.new(headers.size - 1, nil)
end

#formula(row_index, target, pos1, pos2) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
# File 'ui/examples/spreadsheet/csv.rb', line 196

def formula(row_index, target, pos1, pos2)      
  memo = 0

  srow, scol = pos1.split(":")
  erow, ecol = pos2.split(":")

  (srow.to_i..erow.to_i).each do |idx|
    memo += csv[idx][scol.to_i].to_i
  end

  csv[row_index + 1][target] = memo
end

#get_header(index) ⇒ Object



192
193
194
# File 'ui/examples/spreadsheet/csv.rb', line 192

def get_header(index)
  headers[index] || ""
end

#headersObject



241
242
243
# File 'ui/examples/spreadsheet/csv.rb', line 241

def headers
  csv.to_a[0]
end

#row_countObject



237
238
239
# File 'ui/examples/spreadsheet/csv.rb', line 237

def row_count
  csv.to_a.size
end

#row_header(index) ⇒ Object



251
252
253
# File 'ui/examples/spreadsheet/csv.rb', line 251

def row_header(index)
  "header-#{index}"
end

#row_key(index) ⇒ Object



255
256
257
# File 'ui/examples/spreadsheet/csv.rb', line 255

def row_key(index)
  "row-#{index}"
end

#rowsObject



219
220
221
222
223
224
225
226
227
# File 'ui/examples/spreadsheet/csv.rb', line 219

def rows
  (1..row_count).map do |rindex|
    row = csv[rindex] || Array.new(column_count, nil)

    (0..column_count).map do |cindex|
      row[cindex] || ""
    end
  end
end

#update_cell(row_index, cell_index, value) ⇒ Object



209
210
211
212
213
214
215
216
217
# File 'ui/examples/spreadsheet/csv.rb', line 209

def update_cell(row_index, cell_index, value)
  if csv[row_index + 1].nil?
    csv[row_index + 1] = empty_row
  end

  csv[row_index + 1][cell_index] = value

  emit("update", csv)
end