Class: OOXL::Row
- Inherits:
-
Object
- Object
- OOXL::Row
- Includes:
- Enumerable
- Defined in:
- lib/ooxl/xl_objects/row.rb
Constant Summary collapse
- DEFAULT_HEIGHT =
'12.75'
Instance Attribute Summary collapse
-
#cells ⇒ Object
Returns the value of attribute cells.
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
Returns the value of attribute id.
-
#spans ⇒ Object
Returns the value of attribute spans.
Class Method Summary collapse
Instance Method Summary collapse
- #[](id) ⇒ Object
- #cell(cell_id) ⇒ Object
- #cell_id_map ⇒ Object
- #each ⇒ Object
-
#initialize(**attrs) ⇒ Row
constructor
A new instance of Row.
Constructor Details
#initialize(**attrs) ⇒ Row
Returns a new instance of Row.
6 7 8 9 10 |
# File 'lib/ooxl/xl_objects/row.rb', line 6 def initialize(**attrs) attrs.each { |property, value| property == :options ? instance_variable_set("@#{property}", value) : send("#{property}=", value)} @options ||= {} @height ||= DEFAULT_HEIGHT end |
Instance Attribute Details
#cells ⇒ Object
Returns the value of attribute cells.
4 5 6 |
# File 'lib/ooxl/xl_objects/row.rb', line 4 def cells @cells end |
#height ⇒ Object
Returns the value of attribute height.
4 5 6 |
# File 'lib/ooxl/xl_objects/row.rb', line 4 def height @height end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/ooxl/xl_objects/row.rb', line 4 def id @id end |
#spans ⇒ Object
Returns the value of attribute spans.
4 5 6 |
# File 'lib/ooxl/xl_objects/row.rb', line 4 def spans @spans end |
Class Method Details
.extract_id(row_node) ⇒ Object
55 56 57 |
# File 'lib/ooxl/xl_objects/row.rb', line 55 def self.extract_id(row_node) row_node.attributes["r"].try(:value) end |
.load_from_node(row_node, shared_strings, styles, options) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/ooxl/xl_objects/row.rb', line 47 def self.load_from_node(row_node, shared_strings, styles, ) new(id: extract_id(row_node), spans: row_node.attributes["spans"].try(:value), height: row_node.attributes["ht"].try(:value), cells: row_node.xpath('c').map { |cell_node| OOXL::Cell.load_from_node(cell_node, shared_strings, styles)}, options: ) end |
Instance Method Details
#[](id) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/ooxl/xl_objects/row.rb', line 12 def [](id) if id.is_a?(String) cell(id) else cells[id] || BlankCell.new(id) end end |
#cell(cell_id) ⇒ Object
32 33 34 35 |
# File 'lib/ooxl/xl_objects/row.rb', line 32 def cell(cell_id) cell_final_id = cell_id[/[A-Z]+\d+/] ? cell_id : "#{cell_id}#{id}" cell_id_map[cell_final_id] end |
#cell_id_map ⇒ Object
37 38 39 40 41 |
# File 'lib/ooxl/xl_objects/row.rb', line 37 def cell_id_map @cell_id_map ||= cells.each_with_object(Hash.new { |_, k| BlankCell.new(k) }) do |cell, result| result[cell.id] = cell end end |
#each ⇒ Object
43 44 45 |
# File 'lib/ooxl/xl_objects/row.rb', line 43 def each cells.each { |cell| yield cell } end |