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.
- checksums.yaml +4 -4
- data/bin/reading +33 -18
- data/lib/reading/config.rb +2 -2
- data/lib/reading/item/time_length.rb +2 -2
- data/lib/reading/item/view.rb +2 -2
- data/lib/reading/item.rb +15 -12
- data/lib/reading/parsing/attributes/experiences/dates_and_head_transformer.rb +8 -3
- data/lib/reading/parsing/attributes/experiences/history_transformer.rb +151 -48
- data/lib/reading/parsing/attributes/experiences/spans_validator.rb +2 -2
- data/lib/reading/parsing/attributes/experiences.rb +3 -3
- data/lib/reading/parsing/attributes/shared.rb +4 -1
- data/lib/reading/parsing/csv.rb +4 -4
- data/lib/reading/parsing/parser.rb +6 -6
- data/lib/reading/parsing/rows/compact_planned.rb +4 -4
- data/lib/reading/parsing/rows/regular.rb +10 -10
- data/lib/reading/parsing/rows/regular_columns/sources.rb +1 -1
- data/lib/reading/parsing/rows/regular_columns/start_dates.rb +5 -1
- data/lib/reading/parsing/transformer.rb +9 -9
- data/lib/reading/stats/filter.rb +55 -51
- data/lib/reading/stats/grouping.rb +18 -4
- data/lib/reading/stats/operation.rb +104 -22
- data/lib/reading/stats/query.rb +7 -7
- data/lib/reading/stats/result_formatters.rb +140 -0
- data/lib/reading/util/hash_array_deep_fetch.rb +1 -23
- data/lib/reading/version.rb +1 -1
- data/lib/reading.rb +7 -7
- metadata +46 -22
- data/lib/reading/stats/terminal_result_formatters.rb +0 -91
| @@ -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
         |