Class: ATDIS::Models::Page

Inherits:
ATDIS::Model show all
Defined in:
lib/atdis/models/page.rb

Instance Attribute Summary

Attributes inherited from ATDIS::Model

#attributes, #attributes_before_type_cast, #json_left_overs, #json_load_error, #timezone, #url

Instance Method Summary collapse

Methods inherited from ATDIS::Model

attribute_keys, attribute_names, cast, cast_datetime, cast_geojson, cast_integer, cast_string, cast_uri, hash_symbols_to_string, #initialize, interpret, #json_errors, #json_errors_in_children, #json_errors_local, #json_left_overs_is_empty, #json_loaded_correctly!, partition_by_used, read_json, read_url, read_url_raw, #used_attribute?

Constructor Details

This class inherits a constructor from ATDIS::Model

Instance Method Details

#all_pagination_is_presentObject

If some of the pagination fields are present all of the required ones should be present



27
28
29
30
31
# File 'lib/atdis/models/page.rb', line 27

def all_pagination_is_present
  return unless pagination && count.nil?

  errors.add(:count, ErrorMessage["should be present if pagination is being used", "6.4"])
end

#count_is_consistentObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/atdis/models/page.rb', line 33

def count_is_consistent
  return if count.nil?

  if response.respond_to?(:count)
    if count != response.count
      errors.add(
        :count,
        ErrorMessage["is not the same as the number of applications returned", "6.4"]
      )
    end
  end
  return unless pagination.respond_to?(:per_page) && pagination.per_page

  return unless count > pagination.per_page

  errors.add(
    :count,
    ErrorMessage["should not be larger than the number of results per page", "6.4"]
  )
end

#next_pageObject



70
71
72
# File 'lib/atdis/models/page.rb', line 70

def next_page
  Page.read_url(next_url, timezone) if next_url
end

#next_urlObject



60
61
62
63
64
# File 'lib/atdis/models/page.rb', line 60

def next_url
  raise "Can't use next_url when loaded with read_json" if url.nil?

  ATDIS::SeparatedURL.merge(url, page: pagination.next) if pagination&.next
end

#previous_pageObject



66
67
68
# File 'lib/atdis/models/page.rb', line 66

def previous_page
  Page.read_url(previous_url, timezone) if previous_url
end

#previous_urlObject



54
55
56
57
58
# File 'lib/atdis/models/page.rb', line 54

def previous_url
  raise "Can't use previous_url when loaded with read_json" if url.nil?

  ATDIS::SeparatedURL.merge(url, page: pagination.previous) if pagination&.previous
end