Class: OOXL::RowCache
- Inherits:
-
Object
- Object
- OOXL::RowCache
- Includes:
- Enumerable
- Defined in:
- lib/ooxl/xl_objects/row_cache.rb
Instance Attribute Summary collapse
-
#row_cache ⇒ Object
readonly
built on-demand – use rows instead.
-
#row_id_map ⇒ Object
readonly
built on-demand – use fetch_row_by_id instead.
-
#styles ⇒ Object
Returns the value of attribute styles.
Instance Method Summary collapse
- #[](id) ⇒ Object (also: #row)
- #each(&block) ⇒ Object
-
#initialize(sheet_xml, shared_strings, options = {}) ⇒ RowCache
constructor
A new instance of RowCache.
- #max_row_index ⇒ Object
- #row_range(start_index, end_index) ⇒ Object
- #rows(&block) ⇒ Object
Constructor Details
#initialize(sheet_xml, shared_strings, options = {}) ⇒ RowCache
Returns a new instance of RowCache.
15 16 17 18 19 20 21 |
# File 'lib/ooxl/xl_objects/row_cache.rb', line 15 def initialize(sheet_xml, shared_strings, = {}) @shared_strings = shared_strings @sheet_xml = sheet_xml @options = @row_cache = [] @row_id_map = {} end |
Instance Attribute Details
#row_cache ⇒ Object (readonly)
built on-demand – use rows instead
8 9 10 |
# File 'lib/ooxl/xl_objects/row_cache.rb', line 8 def row_cache @row_cache end |
#row_id_map ⇒ Object (readonly)
built on-demand – use fetch_row_by_id instead
11 12 13 |
# File 'lib/ooxl/xl_objects/row_cache.rb', line 11 def row_id_map @row_id_map end |
#styles ⇒ Object
Returns the value of attribute styles.
5 6 7 |
# File 'lib/ooxl/xl_objects/row_cache.rb', line 5 def styles @styles end |
Instance Method Details
#[](id) ⇒ Object Also known as: row
23 24 25 |
# File 'lib/ooxl/xl_objects/row_cache.rb', line 23 def [](id) fetch_row_by_id(id) end |
#each(&block) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/ooxl/xl_objects/row_cache.rb', line 29 def each(&block) if @options[:padded_rows] padded_rows(&block) else rows(&block) end end |
#max_row_index ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/ooxl/xl_objects/row_cache.rb', line 64 def max_row_index return 0 if row_nodes.empty? if all_rows_loaded? row_cache.last.id.to_i else Row.extract_id(row_nodes.last).to_i end end |
#row_range(start_index, end_index) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ooxl/xl_objects/row_cache.rb', line 52 def row_range(start_index, end_index) return enum_for(:row_range, start_index, end_index) unless block_given? rows do |row| row_id = row.id.to_i next if row_id < start_index break if row_id > end_index yield row end end |
#rows(&block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ooxl/xl_objects/row_cache.rb', line 37 def rows(&block) # track yield count to know if caller broke out of loop rows_yielded = 0 row_cache.each do |r| yield r if block_given? rows_yielded += 1 end if !all_rows_loaded? && rows_yielded == row_cache.count parse_more_rows(&block) end row_cache end |