Class: Eagleplatform::Filter
- Inherits:
-
Object
- Object
- Eagleplatform::Filter
- Defined in:
- lib/eagleplatform/filter.rb
Overview
Filters
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total_entries ⇒ Object
readonly
Returns the value of attribute total_entries.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Class Method Summary collapse
-
.find(id, per_page = 50, page = 1) ⇒ Eagleplatform::Filter
Get records form filter.
Instance Method Summary collapse
-
#initialize(result) ⇒ Filter
constructor
private
A new instance of Filter.
-
#next_page ⇒ String
Load records form filter next page.
-
#records ⇒ Array
List of loaded records.
Constructor Details
#initialize(result) ⇒ Filter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Filter.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/eagleplatform/filter.rb', line 38 def initialize(result) @id = result['id'] @name = result['name'] @total_entries = result['total_entries'] @total_pages = result['total_pages'] @current_page = result['current_page'] @records = [] result['records'].each do |record| rec = Eagleplatform::Record.new rec.each_pair { |k,v| rec[k] = record[k.to_s]} @records.push(rec) end notice = <<-EOF ##################################################### ATTENTION - There is more then one page method 'next_page' load more records See: total_pages, current_page and total_enteries ##################################################### EOF puts notice if @total_pages > 1 end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
29 30 31 |
# File 'lib/eagleplatform/filter.rb', line 29 def current_page @current_page end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
29 30 31 |
# File 'lib/eagleplatform/filter.rb', line 29 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/eagleplatform/filter.rb', line 29 def name @name end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
29 30 31 |
# File 'lib/eagleplatform/filter.rb', line 29 def per_page @per_page end |
#total_entries ⇒ Object (readonly)
Returns the value of attribute total_entries.
29 30 31 |
# File 'lib/eagleplatform/filter.rb', line 29 def total_entries @total_entries end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
29 30 31 |
# File 'lib/eagleplatform/filter.rb', line 29 def total_pages @total_pages end |
Class Method Details
.find(id, per_page = 50, page = 1) ⇒ Eagleplatform::Filter
Get records form filter
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/eagleplatform/filter.rb', line 110 def self.find(id, per_page = 50, page = 1) raise 'per_page must be betwen 1 to 1000' unless per_page.between?(1,1000) raise ArgumentError, 'id must be numeric' unless id.is_a? Numeric params = { page: page.to_s, per_page: per_page.to_s } api_method = {method: Methods::FILTER_GET_RECORDS[:method], path: Methods::FILTER_GET_RECORDS[:path].gsub(':id',id.to_s)} result = Eagleplatform.call_api(api_method, params) filter = self.new(result) filter.instance_eval("@per_page = #{per_page}") filter end |
Instance Method Details
#next_page ⇒ String
Load records form filter next page
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/eagleplatform/filter.rb', line 68 def next_page if @current_page < @total_pages begin @current_page += 1 params = { page: @current_page.to_s, per_page: @per_page.to_s } api_method = {method: Methods::FILTER_GET_RECORDS[:method], path: Methods::FILTER_GET_RECORDS[:path].gsub(':id', self.id.to_s)} result = Eagleplatform.call_api(api_method, params) result['records'].each do |record| rec = Eagleplatform::Record.new rec.each_pair { |k,v| rec[k] = record[k.to_s]} @records.push(rec) end puts "+#{result['records'].count} records loaded." rescue Exception => e @current_page -= 1 puts e end elsif @current_page == @total_pages puts "@current_page == @total_pages. Nothing to load" end end |
#records ⇒ Array
List of loaded records
33 34 35 |
# File 'lib/eagleplatform/filter.rb', line 33 def records @records end |