Class: Fastsheet::Sheet

Inherits:
Object
  • Object
show all
Defined in:
lib/fastsheet/sheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name, options = {}) ⇒ Sheet

Returns a new instance of Sheet.



7
8
9
10
11
12
# File 'lib/fastsheet/sheet.rb', line 7

def initialize(file_name, options = {})
  # this method sets @rows, @height and @width
  read!(file_name)

  @header = @rows.shift if options[:header]
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



3
4
5
# File 'lib/fastsheet/sheet.rb', line 3

def file_name
  @file_name
end

#headerObject (readonly)

Returns the value of attribute header.



3
4
5
# File 'lib/fastsheet/sheet.rb', line 3

def header
  @header
end

#heightObject (readonly)

Returns the value of attribute height.



3
4
5
# File 'lib/fastsheet/sheet.rb', line 3

def height
  @height
end

#rowsObject (readonly)

Returns the value of attribute rows.



3
4
5
# File 'lib/fastsheet/sheet.rb', line 3

def rows
  @rows
end

#widthObject (readonly)

Returns the value of attribute width.



3
4
5
# File 'lib/fastsheet/sheet.rb', line 3

def width
  @width
end

Instance Method Details

#column(n) ⇒ Object



26
27
28
# File 'lib/fastsheet/sheet.rb', line 26

def column(n)
  @rows.map { |r| r[n] }
end

#columnsObject



30
31
32
33
34
# File 'lib/fastsheet/sheet.rb', line 30

def columns
  (0...@width).inject([]) do |cols, i|
    cols.push column(i)
  end
end

#each_columnObject



36
37
38
39
40
41
42
# File 'lib/fastsheet/sheet.rb', line 36

def each_column
  if block_given?
    columns.each { |c| yield c }
  else
    columns.each
  end
end

#each_rowObject



18
19
20
21
22
23
24
# File 'lib/fastsheet/sheet.rb', line 18

def each_row
  if block_given?
    @rows.each { |r| yield r }
  else
    @rows.each
  end
end

#row(n) ⇒ Object



14
15
16
# File 'lib/fastsheet/sheet.rb', line 14

def row(n)
  @rows[n]
end