-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaginator.rb
54 lines (39 loc) · 1.16 KB
/
paginator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def get_book_pages(number_of_content_pages)
number_of_content_pages = number_of_content_pages.to_i + 2 # plus front and back cover
multiplier = number_of_content_pages / 4
modulus = number_of_content_pages % 4
if modulus > 0
multiplier = multiplier + 1
end
actual_number_of_pages = multiplier * 4
number_of_blank_pages = actual_number_of_pages - number_of_content_pages
result_array = [actual_number_of_pages, number_of_blank_pages]
end
def pagination(actual_number_of_pages)
number_of_sheets = actual_number_of_pages / 2
sheets = {}
counter = 1
while counter < number_of_sheets + 1
if counter == 1
sheets[1] = [1,actual_number_of_pages]
else
iseven = false
if counter % 2 == 0
iseven = true
end
prev_a = sheets[counter - 1][0]
prev_b = sheets[counter - 1][1]
if iseven
sheets[counter] = [prev_b - 1, prev_a + 1]
else
sheets[counter] = [prev_b + 1, prev_a - 1]
end
end
counter += 1
end
sheets
end
def add_number_blanks(number_of_content_pages,number_of_blank_pages)
number_of_content_pages = number_of_content_pages + number_of_blank_pages
number_of_content_pages
end