Class: Reading::Parsing::Rows::Regular::History

Inherits:
Column show all
Defined in:
lib/reading/parsing/rows/regular_columns/history.rb

Overview

Constant Summary

Constants inherited from Column

Column::SHARED_REGEXES

Class Method Summary collapse

Methods inherited from Column

column_name, flatten_into_arrays, regexes_before_formats, split_by_format?, split_by_segment?, split_by_segment_group?, to_sym

Class Method Details

.regexes(segment_index) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/reading/parsing/rows/regular_columns/history.rb', line 36

def self.regexes(segment_index)
  [
    # entry of exception dates ("but not on these dates")
    %r{\A
      not
      \s+
      (?<except_dates>.+)
    \z}x,
    # normal entry
    %r{\A
      \(?\s*
      # variant, group before first start date
      (
        (
          v(?<variant>\d)
          (\s+|\z)
        )?
        (
          🤝🏼(?<group>.+?)
        )?
        (?=(\d{4}/)?\d\d?/\d\d?)
      )?
      # planned or dates
      (
        (
          (?<planned>\?\?)
          |
          (#{START_END_DATES_REGEX})
        )
        (\s*\)?\s*\z|\s+)
      )?
      # progress
      (
        # requires the at symbol, unlike the shared progress regex in Column
        # and also adds the done option
        (
          (DNF\s+)?@?(?<progress_percent>\d\d?)%
          |
          (DNF\s+)?@p?(?<progress_pages>\d+)p?
          |
          (DNF\s+)?@(?<progress_time>\d+:\d\d)
          |
          # just DNF
          (?<progress_dnf>DNF)
          |
          # done
          (?<progress_done>done)
        )
        (\s*\)?\s*\z|\s+)
      )?
      # amount, repetitions, frequency
      (
        (
          p?(?<amount_pages>\d+)p?
          |
          (?<amount_time>\d+:\d\d)
        )?
        (
          \s*
          x(?<repetitions>\d+)
        )?
        (
          /(?<frequency>day|week|month)
        )?
        (\s*\)?\s*\z|\s+)
      )?
      # favorite, name
      (
        (?<favorite>⭐)?
        \s*
        (?<name>[^\d].*)
      )?
    \z}xo,
  ]
end

.segment_group_separatorObject



11
12
13
# File 'lib/reading/parsing/rows/regular_columns/history.rb', line 11

def self.segment_group_separator
  /\s*----\s*/
end

.segment_separatorObject



7
8
9
# File 'lib/reading/parsing/rows/regular_columns/history.rb', line 7

def self.segment_separator
  /\s*--\s*/
end

.tweaksObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/reading/parsing/rows/regular_columns/history.rb', line 15

def self.tweaks
  {
    except_dates: ->(dates_list) {
      dates_list
        .split(/\s*,\s*/)
        .map { |date|
          date.match(
            %r{\A
              #{START_END_DATES_REGEX}
            \z}xo
          )
          &.named_captures
          &.compact
          &.transform_keys(&:to_sym)
          &.presence
        }
        .compact
    },
  }
end