Class: Creek::Sheet

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

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


17
18
19
20
21
22
23
24
25
26
# File 'lib/creek/sheet.rb', line 17

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


8
9
10
# File 'lib/creek/sheet.rb', line 8

def book
  @book
end

#indexObject (readonly)

Returns the value of attribute index


8
9
10
# File 'lib/creek/sheet.rb', line 8

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name


8
9
10
# File 'lib/creek/sheet.rb', line 8

def name
  @name
end

#ridObject (readonly)

Returns the value of attribute rid


8
9
10
# File 'lib/creek/sheet.rb', line 8

def rid
  @rid
end

#sheetidObject (readonly)

Returns the value of attribute sheetid


8
9
10
# File 'lib/creek/sheet.rb', line 8

def sheetid
  @sheetid
end

#stateObject (readonly)

Returns the value of attribute state


8
9
10
# File 'lib/creek/sheet.rb', line 8

def state
  @state
end

#visibleObject (readonly)

Returns the value of attribute visible


8
9
10
# File 'lib/creek/sheet.rb', line 8

def visible
  @visible
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.


45
46
47
# File 'lib/creek/sheet.rb', line 45

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.


60
61
62
# File 'lib/creek/sheet.rb', line 60

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.


67
68
69
# File 'lib/creek/sheet.rb', line 67

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.


53
54
55
# File 'lib/creek/sheet.rb', line 53

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.


74
75
76
# File 'lib/creek/sheet.rb', line 74

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).


32
33
34
35
36
37
38
39
# File 'lib/creek/sheet.rb', line 32

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