Class: Rasta::Spreadsheet::Bookmark
- Inherits:
-
Object
- Object
- Rasta::Spreadsheet::Bookmark
- Defined in:
- lib/rasta/spreadsheet.rb
Overview
Bookmarks are ways to continue the spreadsheet from a given point. You can start from a specific tab and/or row/col in the spreadsheet. Additionally you can specify the number of pages and/or records to process so a user can start from SheetA and process 2 Sheets in the spreadsheet.
Bookmarks are formatted as follows:
where the Col/Row is an optional parameter. This gives the following bookmarks as possible continuation points:
SheetA start from this sheet SheetA this sheet is style :row, so start from row 10 SheetA this sheet is style :col, so start from column F true use the bookmark stored in .bookmarks
The pagecount allows the user to start at the desired bookmark but only run through 1 or more sheets in the workbook
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
-
#do_not_execute?(how, what) ⇒ Boolean
Returns true when either bookmark is not found or when pagecount has been reached.
-
#found?(how, what) ⇒ Boolean
Check to see if the current record or page matches the bookmark.
-
#initialize(bookmark) ⇒ Bookmark
constructor
A new instance of Bookmark.
Constructor Details
#initialize(bookmark) ⇒ Bookmark
Returns a new instance of Bookmark.
81 82 83 84 85 86 |
# File 'lib/rasta/spreadsheet.rb', line 81 def initialize(bookmark) # Parse the bookmark into it's parts so we can # check for it as we read in the Sheet Records and Cells @page, @record = parse_bookmark(bookmark) raise ArgumentError, "Invalid record '#{@record}' - argument must be a row or column name" if @record && @record !~ /^([A-Z]+|\d+)$/i end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
79 80 81 |
# File 'lib/rasta/spreadsheet.rb', line 79 def page @page end |
#record ⇒ Object
Returns the value of attribute record.
79 80 81 |
# File 'lib/rasta/spreadsheet.rb', line 79 def record @record end |
Instance Method Details
#do_not_execute?(how, what) ⇒ Boolean
Returns true when either bookmark is not found or when pagecount has been reached.
134 135 136 |
# File 'lib/rasta/spreadsheet.rb', line 134 def do_not_execute?(how, what) !found?(how, what) end |
#found?(how, what) ⇒ Boolean
Check to see if the current record or page matches the bookmark. For example, found?(:sheet, [pagename]) or found?(:record, [row/col]) where pagename is the name of the worksheet and row/col could be the row or column depending on the style of the page (eg: ‘A’ or 6)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rasta/spreadsheet.rb', line 92 def found?(how, what) case how when :sheet if @foundpage # Trap the case when a record is specified # for a page and it does not exist if !@foundrecord && what != @page raise Spreadsheet::BookmarkNotFound, "Record #{@record} does not exist on page #{@page}" end true else if what == @page @foundpage = true # Set the foundrecord true so that it always # passes the comparison if the record is not set @foundrecord = true if !@record true else false end end when :record raise Spreadsheet::BookmarkNotFound, 'Should never get here: page should have been found first' if !@foundpage if @foundrecord true else if what == @record @foundrecord = true true else # TODO: RAISE if wrong type. (row is specified but it's a col) false end end else raise ArgumentError, "Don't know how to check bookmark for '#{how}'" end end |