Class: Creeker::Sheet

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/creeker/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/creeker/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/creeker/sheet.rb', line 8

def book
  @book
end

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#ridObject (readonly)

Returns the value of attribute rid.



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

def rid
  @rid
end

#sheetidObject (readonly)

Returns the value of attribute sheetid.



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

def sheetid
  @sheetid
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

#visibleObject (readonly)

Returns the value of attribute visible.



8
9
10
# File 'lib/creeker/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/creeker/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.



52
53
54
# File 'lib/creeker/sheet.rb', line 52

def rows
  rows_generator
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.



59
60
61
# File 'lib/creeker/sheet.rb', line 59

def 
  rows_generator 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/creeker/sheet.rb', line 32

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