Class: Minpaso::SearchResultPager

Inherits:
Object
  • Object
show all
Defined in:
lib/minpaso.rb

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, params) ⇒ SearchResultPager

Returns a new instance of SearchResultPager.



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/minpaso.rb', line 86

def initialize(doc, params)
  @params = params
  @items = []
  doc.root.elements.each do |elt|
    case elt.name
    when "NumOfResult"
      @size = elt.text.to_i
    when "Item"
      @items << Item.new(elt)
    end
  end
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



85
86
87
# File 'lib/minpaso.rb', line 85

def items
  @items
end

#sizeObject (readonly)

Returns the value of attribute size.



85
86
87
# File 'lib/minpaso.rb', line 85

def size
  @size
end

Instance Method Details

#nextObject

Go to next page.



111
112
113
114
115
# File 'lib/minpaso.rb', line 111

def next
  next_page = page + 1
  return nil if next_page >= ((@size - 1) / 10) + 1
  Minpaso.search(@params.merge(:p => next_page))
end

#pageObject



99
100
101
# File 'lib/minpaso.rb', line 99

def page
  @params.has_key?("p") ? @params["p"] : 1
end

#prevObject

Go to previous page.



104
105
106
107
108
# File 'lib/minpaso.rb', line 104

def prev
  prev_page = page - 1
  return nil if prev_page <= 0
  Minpaso.search(@params.merge(:p => prev_page))
end