reading 0.9.0 → 1.0.0

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.
@@ -1,91 +0,0 @@
1
- require 'pastel'
2
-
3
- module Reading
4
- module Stats
5
- module ResultFormatters
6
- TERMINAL = {
7
- average_length: ->(result) { length_to_s(result) },
8
- average_amount: ->(result) { length_to_s(result) },
9
- :'average_daily-amount' => ->(result) { "#{length_to_s(result)} per day" },
10
- total_item: ->(result) {
11
- if result.zero?
12
- PASTEL.bright_black("none")
13
- else
14
- color("#{result} #{result == 1 ? "item" : "items"}")
15
- end
16
- },
17
- total_amount: ->(result) { length_to_s(result) },
18
- top_length: ->(result) { top_or_bottom_lengths(result) },
19
- top_amount: ->(result) { top_or_bottom_lengths(result) },
20
- top_speed: ->(result) { top_or_bottom_speeds(result) },
21
- bottom_length: ->(result) { top_or_bottom_lengths(result) },
22
- botom_amount: ->(result) { top_or_bottom_lengths(result) },
23
- bottom_speed: ->(result) { top_or_bottom_speeds(result) },
24
- }
25
-
26
- private
27
-
28
- PASTEL = Pastel.new
29
-
30
- # Applies a terminal color.
31
- # @param string [String]
32
- # @return [String]
33
- private_class_method def self.color(string)
34
- PASTEL.bright_blue(string)
35
- end
36
-
37
- # Converts a length/amount (pages or time) into a string.
38
- # @param length [Numeric, Reading::Item::TimeLength]
39
- # @param color [Boolean] whether a terminal color should be applied.
40
- # @return [String]
41
- private_class_method def self.length_to_s(length, color: true)
42
- if length.is_a?(Numeric)
43
- length_string = "#{length.round} pages"
44
- else
45
- length_string = length.to_s
46
- end
47
-
48
- color ? color(length_string) : length_string
49
- end
50
-
51
- # Formats a list of top/bottom length results as a string.
52
- # @param result [Array]
53
- # @return [String]
54
- private_class_method def self.top_or_bottom_lengths(result)
55
- offset = result.count.digits.count
56
-
57
- result
58
- .map.with_index { |(title, length), index|
59
- pad = ' ' * (offset - (index + 1).digits.count)
60
-
61
- title_line = "#{index + 1}. #{pad}#{title}"
62
- indent = " #{' ' * offset}"
63
-
64
- "#{title_line}\n#{indent}#{length_to_s(length)}"
65
- }
66
- .join("\n")
67
- end
68
-
69
- # Formats a list of top/bottom speed results as a string.
70
- # @param result [Array]
71
- # @return [String]
72
- private_class_method def self.top_or_bottom_speeds(result)
73
- offset = result.count.digits.count
74
-
75
- result
76
- .map.with_index { |(title, hash), index|
77
- amount = length_to_s(hash[:amount], color: false)
78
- days = "#{hash[:days]} #{hash[:days] == 1 ? "day" : "days"}"
79
- pad = ' ' * (offset - (index + 1).digits.count)
80
-
81
- title_line = "#{index + 1}. #{pad}#{title}"
82
- indent = " #{' ' * offset}"
83
- colored_speed = color("#{amount} in #{days}")
84
-
85
- "#{title_line}\n#{indent}#{colored_speed}"
86
- }
87
- .join("\n")
88
- end
89
- end
90
- end
91
- end