Class: Creek::Sheet
Constant Summary collapse
- HEADERS_ROW_NUMBER =
'1'
- SPREADSHEETML_URI =
'http://schemas.openxmlformats.org/spreadsheetml/2006/main'
Instance Attribute Summary collapse
-
#book ⇒ Object
readonly
Returns the value of attribute book.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rid ⇒ Object
readonly
Returns the value of attribute rid.
-
#sheetid ⇒ Object
readonly
Returns the value of attribute sheetid.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#visible ⇒ Object
readonly
Returns the value of attribute visible.
-
#with_headers ⇒ Object
Returns the value of attribute with_headers.
Instance Method Summary collapse
-
#images_at(cell) ⇒ Object
Extracts images for a cell to a temporary folder.
-
#initialize(book, name, sheetid, state, visible, rid, sheetfile) ⇒ Sheet
constructor
A new instance of Sheet.
-
#rows ⇒ Object
Provides an Enumerator that returns a hash representing each row.
-
#rows_with_meta_data ⇒ Object
Provides an Enumerator that returns a hash representing each row.
-
#simple_rows ⇒ Object
Provides an Enumerator that returns a hash representing each row.
-
#simple_rows_with_meta_data ⇒ Object
Provides an Enumerator that returns a hash representing each row.
-
#with_images ⇒ Object
Preloads images info (coordinates and paths) from related drawing.xml and drawing rels.
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
#book ⇒ Object (readonly)
Returns the value of attribute book.
14 15 16 |
# File 'lib/creek/sheet.rb', line 14 def book @book end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
14 15 16 |
# File 'lib/creek/sheet.rb', line 14 def headers @headers end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
14 15 16 |
# File 'lib/creek/sheet.rb', line 14 def index @index end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/creek/sheet.rb', line 14 def name @name end |
#rid ⇒ Object (readonly)
Returns the value of attribute rid.
14 15 16 |
# File 'lib/creek/sheet.rb', line 14 def rid @rid end |
#sheetid ⇒ Object (readonly)
Returns the value of attribute sheetid.
14 15 16 |
# File 'lib/creek/sheet.rb', line 14 def sheetid @sheetid end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
14 15 16 |
# File 'lib/creek/sheet.rb', line 14 def state @state end |
#visible ⇒ Object (readonly)
Returns the value of attribute visible.
14 15 16 |
# File 'lib/creek/sheet.rb', line 14 def visible @visible end |
#with_headers ⇒ Object
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 |
#rows ⇒ Object
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_data ⇒ Object
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_rows ⇒ Object
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_data ⇒ Object
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_images ⇒ Object
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 |