jsondb 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jsondb/paginated_hash.rb +30 -0
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec92f4dc89f2633920502a33f1fc20b2c21cf8c4
4
- data.tar.gz: 8c48bbe8570921690c3ea7b732a87ab84bc9f8fc
3
+ metadata.gz: 9dc6dbddbf1fa0419c9e8b71716edbda6c1d6f12
4
+ data.tar.gz: 1a6b44c598486d305486cddb751c583e89d17c80
5
5
  SHA512:
6
- metadata.gz: 716f92939eeefba92fc83ce4bfc9b4242f8f79046c9dd947bdd8baf1d1fb115af8cafe0069d171acf31332b1450dd07915a0a5582a7e07cb40119dcf64cb7eb6
7
- data.tar.gz: d19526b19c58b6c0d75a88c9270ab3d85ba432f1b39921ce93fd18bd13fab51adc728512ba61f881dbd1549ac24fef52d242cdf2475e6127a1c9028bc3cef3af
6
+ metadata.gz: 699f779814d22f2b9ffcb67595c09ad8f47ef6539d26abd80f4201099a15fb7cacfa71fa10110b9fa293536768d5daf342714db30de2d0d5fc20e2a98ca43d33
7
+ data.tar.gz: 49f9770516e1a584ef5e4c58de8936293697c3518e568770e9577570e78f2310c7a650a75a52b7dcadb3ff4539838e9cdd07022b75b95f17a7b8dc645c6cf394
@@ -0,0 +1,30 @@
1
+ module JSONdb
2
+
3
+ class PaginatedHash < Hash
4
+
5
+ attr_accessor :per_page
6
+
7
+ def initialize
8
+ super
9
+ @per_page = 20
10
+ end
11
+
12
+ def page(page_number)
13
+ first_item = @per_page * (page_number - 1)
14
+ last_item = first_item + (@per_page - 1)
15
+ keys_to_include = keys[first_item..last_item]
16
+ new_hash = self.select { |k, v| keys_to_include.include?(k) }
17
+ return new_hash
18
+ end
19
+
20
+ def total_pages
21
+ # pages = all keys divided by per_page, giving a integer result without mod
22
+ pages = self.keys.count / @per_page
23
+ # pages = pages + 1 if there are some modulo after that calculation
24
+ # so 0 / 20 = 0 + 0 ; 1 /20 = 0 + 1 ; 60 / 20 = 3 + 0 ; 65 / 20 = 3 + 1
25
+ pages = pages + 1 if self.keys.count % @per_page > 0
26
+ return pages
27
+ end
28
+ end
29
+
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsondb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Fernandez
@@ -39,6 +39,7 @@ files:
39
39
  - lib/jsondb/fields.rb
40
40
  - lib/jsondb/file_ops.rb
41
41
  - lib/jsondb/logger.rb
42
+ - lib/jsondb/paginated_hash.rb
42
43
  - lib/jsondb/record.rb
43
44
  - lib/jsondb/records.rb
44
45
  - lib/jsondb/result_set.rb