Class: RDBr::Query::Page

Inherits:
Data
  • Object
show all
Defined in:
lib/rdbr/query/page.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns

Returns:

  • (Object)

    the current value of columns



6
7
8
# File 'lib/rdbr/query/page.rb', line 6

def columns
  @columns
end

#has_nextObject (readonly)

Returns the value of attribute has_next

Returns:

  • (Object)

    the current value of has_next



6
7
8
# File 'lib/rdbr/query/page.rb', line 6

def has_next
  @has_next
end

#namespaceObject (readonly)

Returns the value of attribute namespace

Returns:

  • (Object)

    the current value of namespace



6
7
8
# File 'lib/rdbr/query/page.rb', line 6

def namespace
  @namespace
end

#pageObject (readonly)

Returns the value of attribute page

Returns:

  • (Object)

    the current value of page



6
7
8
# File 'lib/rdbr/query/page.rb', line 6

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page

Returns:

  • (Object)

    the current value of per_page



6
7
8
# File 'lib/rdbr/query/page.rb', line 6

def per_page
  @per_page
end

#relationObject (readonly)

Returns the value of attribute relation

Returns:

  • (Object)

    the current value of relation



6
7
8
# File 'lib/rdbr/query/page.rb', line 6

def relation
  @relation
end

#rowsObject (readonly)

Returns the value of attribute rows

Returns:

  • (Object)

    the current value of rows



6
7
8
# File 'lib/rdbr/query/page.rb', line 6

def rows
  @rows
end

#total_countObject (readonly)

Returns the value of attribute total_count

Returns:

  • (Object)

    the current value of 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_hObject



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_pagesObject



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