Class: Vedeu::Models::Page
- Inherits:
-
Object
- Object
- Vedeu::Models::Page
- Includes:
- Enumerable
- Defined in:
- lib/vedeu/models/page.rb
Overview
A Page represents an array of Vedeu::Models::Row objects.
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #cell(row_index = nil, cell_index = nil) ⇒ NilClass|void
- #content ⇒ Array<void>
-
#each(&block) ⇒ Enumerator
Provides iteration over the collection.
- #empty? ⇒ Boolean
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#initialize(rows = []) ⇒ Vedeu::Models::Page
constructor
Returns an instance of Vedeu::Models::Page.
- #row(index = nil) ⇒ NilClass|Vedeu::Models::Row
Constructor Details
#initialize(rows = []) ⇒ Vedeu::Models::Page
Returns an instance of Vedeu::Models::Page.
44 45 46 |
# File 'lib/vedeu/models/page.rb', line 44 def initialize(rows = []) @rows = rows || [] end |
Instance Attribute Details
#rows ⇒ Array<NilClass|Vedeu::Models::Row> (readonly)
13 14 15 |
# File 'lib/vedeu/models/page.rb', line 13 def rows @rows end |
Class Method Details
.coerce(value) ⇒ Vedeu::Models::Page
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vedeu/models/page.rb', line 18 def self.coerce(value) if value.is_a?(Vedeu::Models::Page) value elsif value.is_a?(Vedeu::Models::Row) Vedeu::Models::Page.new([value]) elsif value.is_a?(Array) && value.empty? Vedeu::Models::Page.new([Vedeu::Models::Row.coerce(value)]) elsif value.is_a?(Array) values = value.map { |v| Vedeu::Models::Row.coerce(v) } Vedeu::Models::Page.new(values) else fail Vedeu::Error::InvalidSyntax, 'Cannot coerce as value is not an Array.'.freeze end end |
Instance Method Details
#cell(row_index = nil, cell_index = nil) ⇒ NilClass|void
56 57 58 59 60 61 |
# File 'lib/vedeu/models/page.rb', line 56 def cell(row_index = nil, cell_index = nil) return nil if row_index.nil? || cell_index.nil? return nil unless row(row_index) row(row_index)[cell_index] end |
#content ⇒ Array<void>
49 50 51 |
# File 'lib/vedeu/models/page.rb', line 49 def content rows.flat_map(&:content) end |
#each(&block) ⇒ Enumerator
Provides iteration over the collection.
67 68 69 |
# File 'lib/vedeu/models/page.rb', line 67 def each(&block) rows.each(&block) end |
#empty? ⇒ Boolean
72 73 74 |
# File 'lib/vedeu/models/page.rb', line 72 def empty? rows.empty? end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
80 81 82 |
# File 'lib/vedeu/models/page.rb', line 80 def eql?(other) self.class == other.class && rows == other.rows end |
#row(index = nil) ⇒ NilClass|Vedeu::Models::Row
87 88 89 90 91 |
# File 'lib/vedeu/models/page.rb', line 87 def row(index = nil) return nil if index.nil? rows[index] end |