Class: Creek::Sheet

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/creek/sheet.rb

Constant Summary collapse

HEADERS_ROW_NUMBER =
'1'
SPREADSHEETML_URI =
'http://schemas.openxmlformats.org/spreadsheetml/2006/main'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#expand_to_rels_path, #file_exist?, #parse_xml

Constructor Details

#initialize(book, name, sheetid, state, visible, rid, sheetfile) ⇒ Sheet

Returns a new instance of Sheet.



23
24
25
26
27
28
29
30
31
32
# File 'lib/creek/sheet.rb', line 23

def initialize(book, name, sheetid, state, visible, rid, sheetfile)
  @book = book
  @name = name
  @sheetid = sheetid
  @visible = visible
  @rid = rid
  @state = state
  @sheetfile = sheetfile
  @images_present = false
end

Instance Attribute Details

#bookObject (readonly)

Returns the value of attribute book.



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

def book
  @book
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#ridObject (readonly)

Returns the value of attribute rid.



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

def rid
  @rid
end

#sheetidObject (readonly)

Returns the value of attribute sheetid.



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

def sheetid
  @sheetid
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

#visibleObject (readonly)

Returns the value of attribute visible.



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

def visible
  @visible
end

#with_headersObject

Returns the value of attribute with_headers.



13
14
15
# File 'lib/creek/sheet.rb', line 13

def with_headers
  @with_headers
end

Instance Method Details

#images_at(cell) ⇒ Object

Extracts images for a cell to a temporary folder. Returns array of Pathnames for the cell. Returns nil if images asre not found for the cell or images were not preloaded with #with_images.



51
52
53
# File 'lib/creek/sheet.rb', line 51

def images_at(cell)
  @drawing.images_at(cell) if @images_present
end

#rowsObject

Provides an Enumerator that returns a hash representing each row. The key of the hash is the Cell id and the value is the value of the cell.



65
66
67
# File 'lib/creek/sheet.rb', line 65

def rows
  rows_generator false, false
end

#rows_with_meta_dataObject

Provides an Enumerator that returns a hash representing each row. The hash contains meta data of the row and a ‘cells’ embended hash which contains the cell contents.



72
73
74
# File 'lib/creek/sheet.rb', line 72

def 
  rows_generator true, false
end

#simple_rowsObject

Provides an Enumerator that returns a hash representing each row. The key of the hash is the column ID and the value is the value of the cell.



58
59
60
# File 'lib/creek/sheet.rb', line 58

def simple_rows
  rows_generator false, true
end

#simple_rows_with_meta_dataObject

Provides an Enumerator that returns a hash representing each row. The hash contains meta data of the row and a ‘cells’ embended hash which contains the cell contents.



79
80
81
# File 'lib/creek/sheet.rb', line 79

def 
  rows_generator true, true
end

#with_imagesObject

Preloads images info (coordinates and paths) from related drawing.xml and drawing rels. Must be called before #rows method if you want to have images included. Returns self so you can chain the calls (sheet.with_images.rows).



38
39
40
41
42
43
44
45
# File 'lib/creek/sheet.rb', line 38

def with_images
  @drawingfile = extract_drawing_filepath
  if @drawingfile
    @drawing = Creek::Drawing.new(@book, @drawingfile.sub('..', 'xl'))
    @images_present = @drawing.has_images?
  end
  self
end