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 a new instance of Vedeu::Models::Page.
- #row(index = nil) ⇒ NilClass|Vedeu::Models::Row
- #size ⇒ Fixnum
Constructor Details
#initialize(rows = []) ⇒ Vedeu::Models::Page
Returns a new instance of Vedeu::Models::Page.
48 49 50 |
# File 'lib/vedeu/models/page.rb', line 48 def initialize(rows = []) @rows = rows || [] end |
Instance Attribute Details
#rows ⇒ Array<NilClass|Vedeu::Models::Row> (readonly)
15 16 17 |
# File 'lib/vedeu/models/page.rb', line 15 def rows @rows end |
Class Method Details
.coerce(value) ⇒ Vedeu::Models::Page
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vedeu/models/page.rb', line 21 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) || value.is_a?(Vedeu::Buffers::View) 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, Vedeu::Models::Page ' \ "or Vedeu::Models::Row. Is a '#{value.class.name}'." end end |
Instance Method Details
#cell(row_index = nil, cell_index = nil) ⇒ NilClass|void
60 61 62 63 64 65 |
# File 'lib/vedeu/models/page.rb', line 60 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>
53 54 55 |
# File 'lib/vedeu/models/page.rb', line 53 def content rows.flat_map(&:content) end |
#each(&block) ⇒ Enumerator
Provides iteration over the collection.
71 72 73 |
# File 'lib/vedeu/models/page.rb', line 71 def each(&block) rows.each(&block) end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
84 85 86 |
# File 'lib/vedeu/models/page.rb', line 84 def eql?(other) self.class == other.class && rows == other.rows end |
#row(index = nil) ⇒ NilClass|Vedeu::Models::Row
91 92 93 94 95 |
# File 'lib/vedeu/models/page.rb', line 91 def row(index = nil) return nil if index.nil? rows[index] end |
#size ⇒ Fixnum
98 99 100 |
# File 'lib/vedeu/models/page.rb', line 98 def size rows.size end |