Class: AMEE::Limiter

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

xmlpathpreamble

Constructor Details

#initialize(data) ⇒ Limiter

Returns a new instance of Limiter.



76
77
78
79
80
# File 'lib/amee/pager.rb', line 76

def initialize(data)
  @offset=data[:resultStart] || 0
  @limit=data[:resultLimit] || 10
  @truncated=data[:truncated] || false
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



81
82
83
# File 'lib/amee/pager.rb', line 81

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



81
82
83
# File 'lib/amee/pager.rb', line 81

def offset
  @offset
end

#truncatedObject (readonly)

Returns the value of attribute truncated.



81
82
83
# File 'lib/amee/pager.rb', line 81

def truncated
  @truncated
end

Class Method Details

.from_json(doc, options = {}) ⇒ Object

Raises:



95
96
97
# File 'lib/amee/pager.rb', line 95

def self.from_json(doc,options={})
  raise AMEE::NotSupported
end

.from_xml(node, options = {}) ⇒ Object



98
99
100
101
102
# File 'lib/amee/pager.rb', line 98

def self.from_xml(node,options={})
  t=x('@truncated',:doc=>node)
  options[:truncated] = (t=='true') if t
  Limiter.new options
end

Instance Method Details

#more?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/amee/pager.rb', line 82

def more?
  truncated
end

#next!Object



85
86
87
88
# File 'lib/amee/pager.rb', line 85

def next!
  @offset+=limit
  more?
end

#optionsObject



92
93
94
# File 'lib/amee/pager.rb', line 92

def options
  {:resultStart=>offset,:resultLimit=>limit}
end

#page_fragmentObject



89
90
91
# File 'lib/amee/pager.rb', line 89

def page_fragment
  "?resultStart=#{offset}&resultLimit=#{limit}"
end