Class: AMEE::Pager

Inherits:
Object
  • Object
show all
Extended by:
ParseHelper
Defined in:
lib/amee/pager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ParseHelper

load_xml_doc, node_value, xmlpathpreamble

Constructor Details

#initialize(data) ⇒ Pager

Returns a new instance of Pager.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/amee/pager.rb', line 8

def initialize(data)
  @start = data[:start]
  @from = data[:from]
  @to = data[:to]
  @items = data[:items]
  @current_page = data[:current_page]
  @requested_page = data[:requested_page]
  @next_page = data[:next_page]
  @previous_page = data[:previous_page]
  @last_page = data[:last_page]
  @items_per_page = data[:items_per_page]
  @items_found = data[:items_found]
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



26
27
28
# File 'lib/amee/pager.rb', line 26

def current_page
  @current_page
end

#fromObject (readonly)

Returns the value of attribute from.



23
24
25
# File 'lib/amee/pager.rb', line 23

def from
  @from
end

#itemsObject (readonly)

Returns the value of attribute items.



25
26
27
# File 'lib/amee/pager.rb', line 25

def items
  @items
end

#items_foundObject (readonly)

Returns the value of attribute items_found.



32
33
34
# File 'lib/amee/pager.rb', line 32

def items_found
  @items_found
end

#items_per_pageObject (readonly)

Returns the value of attribute items_per_page.



31
32
33
# File 'lib/amee/pager.rb', line 31

def items_per_page
  @items_per_page
end

#last_pageObject (readonly)

Returns the value of attribute last_page.



30
31
32
# File 'lib/amee/pager.rb', line 30

def last_page
  @last_page
end

#next_pageObject (readonly)

Returns the value of attribute next_page.



28
29
30
# File 'lib/amee/pager.rb', line 28

def next_page
  @next_page
end

#previous_pageObject (readonly)

Returns the value of attribute previous_page.



29
30
31
# File 'lib/amee/pager.rb', line 29

def previous_page
  @previous_page
end

#requested_pageObject (readonly)

Returns the value of attribute requested_page.



27
28
29
# File 'lib/amee/pager.rb', line 27

def requested_page
  @requested_page
end

#startObject (readonly)

Returns the value of attribute start.



22
23
24
# File 'lib/amee/pager.rb', line 22

def start
  @start
end

#toObject (readonly)

Returns the value of attribute to.



24
25
26
# File 'lib/amee/pager.rb', line 24

def to
  @to
end

Class Method Details

.from_json(node) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/amee/pager.rb', line 49

def self.from_json(node)
  return nil if node.nil? || node.empty?
  return Pager.new({:start => node["start"],
                    :from => node["from"],
                    :to => node["to"],
                    :items => node["items"],
                    :current_page => node["currentPage"],
                    :requested_page => node["requestedPage"],
                    :next_page => node["nextPage"],
                    :previous_page => node["previousPage"],
                    :last_page => node["lastPage"],
                    :items_per_page => node["itemsPerPage"],
                    :items_found => node["itemsFound"]})
end

.from_xml(node) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/amee/pager.rb', line 34

def self.from_xml(node)
  return nil if node.nil? || node.elements.empty?
  return Pager.new({:start => x("Start", :doc => node).to_i,
                    :from => x("From", :doc => node).to_i,
                    :to => x("To", :doc => node).to_i,
                    :items => x("Items", :doc => node).to_i,
                    :current_page => x("CurrentPage", :doc => node).to_i,
                    :requested_page => x("RequestedPage", :doc => node).to_i,
                    :next_page => x("NextPage", :doc => node).to_i,
                    :previous_page => x("PreviousPage", :doc => node).to_i,
                    :last_page => x("LastPage", :doc => node).to_i,
                    :items_per_page => x("ItemsPerPage", :doc => node).to_i,
                    :items_found => x("ItemsFound", :doc => node).to_i})
end

Instance Method Details

#more?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/amee/pager.rb', line 63

def more?
  current_page<=last_page
end

#next!Object



66
67
68
69
# File 'lib/amee/pager.rb', line 66

def next!
  @current_page+=1
  more?
end

#optionsObject



73
74
75
# File 'lib/amee/pager.rb', line 73

def options
  {:page => current_page}
end

#page_fragmentObject



70
71
72
# File 'lib/amee/pager.rb', line 70

def page_fragment
  "?page=#{current_page}"
end