Class: Terrain::Page
- Inherits:
-
Object
- Object
- Terrain::Page
- Defined in:
- lib/terrain/page.rb
Defined Under Namespace
Classes: RangeError
Constant Summary collapse
- RANGE_REGEX =
/^(?<from>[0-9]*)-(?<to>[0-9]*)$/
Instance Attribute Summary collapse
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #bounds ⇒ Object
- #content_range ⇒ Object
- #count ⇒ Object
-
#initialize(scope, range = nil) ⇒ Page
constructor
A new instance of Page.
- #records ⇒ Object
Constructor Details
#initialize(scope, range = nil) ⇒ Page
Returns a new instance of Page.
9 10 11 12 |
# File 'lib/terrain/page.rb', line 9 def initialize(scope, range = nil) @scope = scope @range = range end |
Instance Attribute Details
#range ⇒ Object (readonly)
Returns the value of attribute range.
7 8 9 |
# File 'lib/terrain/page.rb', line 7 def range @range end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
7 8 9 |
# File 'lib/terrain/page.rb', line 7 def scope @scope end |
Instance Method Details
#bounds ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 ⇒ Object
39 40 41 42 43 44 45 46 47 |
# 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 ⇒ Object
29 30 31 |
# File 'lib/terrain/page.rb', line 29 def count @count ||= scope.count end |