class Terrain::Page
Constants
- RANGE_REGEX
Attributes
range[R]
scope[R]
Public Class Methods
new(scope, range = nil)
click to toggle source
# File lib/terrain/page.rb, line 9 def initialize(scope, range = nil) @scope = scope @range = range end
Public Instance Methods
bounds()
click to toggle source
# File lib/terrain/page.rb, line 14 def bounds @bounds ||= begin if range.present? if match raise RangeError if from > to [from, to] else raise RangeError end else [0, count - 1] end end end
content_range()
click to toggle source
# File lib/terrain/page.rb, line 39 def content_range if count > 0 from, to = bounds to = [to, from + records.count - 1].min "#{from}-#{to}/#{count}" else '*/0' end end
count()
click to toggle source
# File lib/terrain/page.rb, line 29 def count @count ||= scope.count end
records()
click to toggle source
# File lib/terrain/page.rb, line 33 def records from, to = bounds limit = [to - from + 1, Terrain.config.max_records].min @records ||= scope.offset(from).limit(limit) end
Private Instance Methods
from()
click to toggle source
# File lib/terrain/page.rb, line 55 def from match && match[:from].present? ? match[:from].to_i : 0 end
match()
click to toggle source
# File lib/terrain/page.rb, line 51 def match range.match(RANGE_REGEX) end
to()
click to toggle source
# File lib/terrain/page.rb, line 59 def to match && match[:to].present? ? match[:to].to_i : (count - 1) end