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

load_xml_doc, node_value, xmlpathpreamble

Constructor Details

#initialize(data) ⇒ Limiter

Returns a new instance of Limiter.



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

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.



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

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



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

def offset
  @offset
end

#truncatedObject (readonly)

Returns the value of attribute truncated.



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

def truncated
  @truncated
end

Class Method Details

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

Raises:



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

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

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



102
103
104
105
106
# File 'lib/amee/pager.rb', line 102

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)


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

def more?
  truncated
end

#next!Object



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

def next!
  @offset+=limit
  more?
end

#optionsObject



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

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

#page_fragmentObject



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

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