page_up 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5ad4acae0705e1d734bd9cdddcb60e282a29f91
4
+ data.tar.gz: 26f1187a297d1a4d79e2fc2872e901934d6c1dfc
5
+ SHA512:
6
+ metadata.gz: 928945d37265bd686037eab1a417ffdd28b79e31af7b6a03544441dc2d4cc7114c703cf570185c6526d8f77ff2cc912e234667dcdd29c0c2409d0175d17d968c
7
+ data.tar.gz: e84c3c0e80972f7bed16b7691b96c98725146ea5a9f2bd56b95c4e1c39f5be523a726965b1c6af9f3876d87dbe23ace1bab97fab2ea3a4ae3dc4dd683374e67a
checksums.yaml.gz.sig ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in page_up.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jon Rowe
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # PageUp
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'page_up'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install page_up
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,57 @@
1
+ module PageUp
2
+ class Pages < SimpleDelegator
3
+
4
+ def initialize collection, page, per_page
5
+ @page = parse page, 1
6
+ @per_page = parse per_page, 25
7
+ @origin = collection
8
+ super collection[page_range]
9
+ end
10
+
11
+ def pages
12
+ (@origin.size.to_f / per_page).ceil
13
+ end
14
+
15
+ def current_slice
16
+ slice_start..slice_end
17
+ end
18
+
19
+ attr_reader :page, :per_page
20
+
21
+ private
22
+ def page_range
23
+ current_page...current_page+per_page
24
+ end
25
+
26
+ def current_page
27
+ (page-1)*per_page
28
+ end
29
+
30
+ def parse value, default
31
+ Integer(value)
32
+ rescue TypeError
33
+ default
34
+ end
35
+
36
+ def slice_start
37
+ if page - 2 <= 0
38
+ 1
39
+ elsif page + 2 > pages
40
+ pages - 4
41
+ else
42
+ page - 2
43
+ end
44
+ end
45
+
46
+ def slice_end
47
+ if page + 2 > pages
48
+ pages
49
+ elsif page - 2 <= 0
50
+ 5
51
+ else
52
+ page + 2
53
+ end
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module PageUp
2
+ VERSION = "0.0.1"
3
+ end
data/lib/page_up.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'page_up/pages'
2
+
3
+ module PageUp
4
+
5
+ def self.[] collection, page = nil, per_page = nil
6
+ PageUp::Pages.new(collection, page, per_page)
7
+ end
8
+
9
+ end
data/page_up.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'page_up/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "page_up"
8
+ spec.version = PageUp::VERSION
9
+ spec.required_ruby_version = ">= 1.9.3"
10
+ spec.authors = ["Jon Rowe"]
11
+ spec.email = ["hello@jonrowe.co.uk"]
12
+ spec.description = %q{Simple paginator}
13
+ spec.summary = %q{Simple paginator}
14
+ spec.homepage = "https://github.com/JonRowe/page_up"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rspec", "~> 2.14.0.rc0"
25
+ end
@@ -0,0 +1,44 @@
1
+ require 'delegate'
2
+ require 'page_up'
3
+
4
+ describe "pagination" do
5
+ let(:collection) { (1..12).to_a }
6
+
7
+ it 'defaults to page 1' do
8
+ expect(PageUp[collection].page).to eq 1
9
+ end
10
+
11
+ it 'defaults to 25 per page' do
12
+ expect(PageUp[collection].per_page).to eq 25
13
+ end
14
+
15
+ it 'handles collections below page count' do
16
+ expect(PageUp[collection]).to eq collection
17
+ end
18
+
19
+ it 'paginates collections above page count' do
20
+ expect(PageUp[collection,1,5]).to eq [1,2,3,4,5]
21
+ expect(PageUp[collection,2,5]).to eq [6,7,8,9,10]
22
+ expect(PageUp[collection,3,5]).to eq [11,12]
23
+ end
24
+
25
+ it 'counts pages' do
26
+ expect(PageUp[collection,1,5].pages).to eq 3
27
+ end
28
+
29
+ describe 'picking the current slice' do
30
+ specify { expect(PageUp[collection,1,1].current_slice).to eq 1..5 }
31
+ specify { expect(PageUp[collection,2,1].current_slice).to eq 1..5 }
32
+ specify { expect(PageUp[collection,3,1].current_slice).to eq 1..5 }
33
+ specify { expect(PageUp[collection,4,1].current_slice).to eq 2..6 }
34
+ specify { expect(PageUp[collection,5,1].current_slice).to eq 3..7 }
35
+ specify { expect(PageUp[collection,6,1].current_slice).to eq 4..8 }
36
+ specify { expect(PageUp[collection,7,1].current_slice).to eq 5..9 }
37
+ specify { expect(PageUp[collection,8,1].current_slice).to eq 6..10 }
38
+ specify { expect(PageUp[collection,9,1].current_slice).to eq 7..11 }
39
+ specify { expect(PageUp[collection,10,1].current_slice).to eq 8..12 }
40
+ specify { expect(PageUp[collection,11,1].current_slice).to eq 8..12 }
41
+ specify { expect(PageUp[collection,12,1].current_slice).to eq 8..12 }
42
+ end
43
+
44
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: page_up
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jon Rowe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDVjCCAj6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBRMQ4wDAYDVQQDDAVoZWxs
14
+ bzEXMBU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CyIfJKn5Ya3JahWQaWIsXf
30
+ /NPE/mB57TOwj+d7XUa2NC4HUadF8R51IYEcIB0PpIEzJlKtfXFcOZxO
31
+ -----END CERTIFICATE-----
32
+ date: 2013-07-01 00:00:00.000000000 Z
33
+ dependencies:
34
+ - !ruby/object:Gem::Dependency
35
+ name: rake
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.0.rc0
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.14.0.rc0
76
+ description: Simple paginator
77
+ email:
78
+ - hello@jonrowe.co.uk
79
+ executables: []
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - .gitignore
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - lib/page_up.rb
89
+ - lib/page_up/pages.rb
90
+ - lib/page_up/version.rb
91
+ - page_up.gemspec
92
+ - spec/page_up/pages_spec.rb
93
+ homepage: https://github.com/JonRowe/page_up
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: 1.9.3
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Simple paginator
117
+ test_files:
118
+ - spec/page_up/pages_spec.rb
metadata.gz.sig ADDED
Binary file