Class: RDBr::Query::Page
- Inherits:
-
Data
- Object
- Data
- RDBr::Query::Page
- Defined in:
- lib/rdbr/query/page.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#has_next ⇒ Object
readonly
Returns the value of attribute has_next.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns
6 7 8 |
# File 'lib/rdbr/query/page.rb', line 6 def columns @columns end |
#has_next ⇒ Object (readonly)
Returns the value of attribute has_next
6 7 8 |
# File 'lib/rdbr/query/page.rb', line 6 def has_next @has_next end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace
6 7 8 |
# File 'lib/rdbr/query/page.rb', line 6 def namespace @namespace end |
#page ⇒ Object (readonly)
Returns the value of attribute page
6 7 8 |
# File 'lib/rdbr/query/page.rb', line 6 def page @page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page
6 7 8 |
# File 'lib/rdbr/query/page.rb', line 6 def per_page @per_page end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation
6 7 8 |
# File 'lib/rdbr/query/page.rb', line 6 def relation @relation end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows
6 7 8 |
# File 'lib/rdbr/query/page.rb', line 6 def rows @rows end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count
6 7 8 |
# File 'lib/rdbr/query/page.rb', line 6 def total_count @total_count end |
Class Method Details
.build(**attributes) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rdbr/query/page.rb', line 7 def self.build(**attributes) new( namespace: attributes.fetch(:namespace).to_s.freeze, relation: attributes.fetch(:relation).to_s.freeze, columns: attributes.fetch(:columns).map{|column| column.to_s.freeze }.freeze, rows: normalize_rows(attributes.fetch(:rows)), page: Integer(attributes.fetch(:page)), per_page: Integer(attributes.fetch(:per_page)), has_next: !!attributes.fetch(:has_next), total_count: attributes[:total_count]&.then{|count| Integer(count) } ) end |
Instance Method Details
#to_h ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rdbr/query/page.rb', line 26 def to_h { namespace: namespace, relation: relation, columns: columns, rows: rows, page: page, per_page: per_page, has_next: has_next, total_count: total_count, total_pages: total_pages } end |
#total_pages ⇒ Object
20 21 22 23 24 |
# File 'lib/rdbr/query/page.rb', line 20 def total_pages return unless total_count [ (total_count.to_f / per_page).ceil, 1 ].max end |