reading 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70825fd8a882da595b06db4f8a0766962dd71b8149248ada3ed55280d68b2975
4
- data.tar.gz: 124c660e9888c712a8bedc05156700b3e233300a8fe9806dd36ec168e910bfea
3
+ metadata.gz: a4145847e60a6045a1381afe207be44d30636ca7b058d4c1c1e0db70009af0b4
4
+ data.tar.gz: 833b042be4b575e4ed166d0269610504c031d03460a0f75c4dedc214b1eaf152
5
5
  SHA512:
6
- metadata.gz: 174a7a35761e5a26569651bee4e7ddefd0bbe8592b3828df34cb9f465d0a734876a57bb0fecb04683c470567a0df151289c375213cdf7ad67d632d8d06d02d10
7
- data.tar.gz: 0cec333e90f2a701521d06c4924083e137268112c1a2749effb17b952b3028a4f4deae9ababd9ce1592eb0a21ba60afac75c0e18f81762af936306d86f2adb82
6
+ metadata.gz: '09f08e0be8d6cd97481097d4193209af3cda404e076f2d5529c7c4bdee5f146afbf980a2cb05f2435c06633b89954067ee8bea9d02dae4eddd924f86626a9f63'
7
+ data.tar.gz: 3a50b075c63f2a8b0082b309bef201a8351344c729e90b18482b5796a53bedee1af7fad71af3a0dd884d1245440cfd14dbf6d28aa38bdf5d09717059bd22e7f8
data/bin/reading CHANGED
@@ -7,8 +7,8 @@
7
7
  # reading "<CSV string>" "<optional comma-separated names of enabled columns>`
8
8
  #
9
9
  # Examples:
10
- # reading '3|📕Trying|Lexpub 1970147288'
11
- # reading '📕Trying|Lexpub 1970147288' 'head, sources'
10
+ # reading '3|📕Trying|Little Library 1970147288'
11
+ # reading '📕Trying|Little Library 1970147288' 'head, sources'
12
12
 
13
13
 
14
14
  require_relative "../lib/reading/csv"
@@ -16,7 +16,7 @@ require "amazing_print"
16
16
 
17
17
  input = ARGV[0]
18
18
  unless input
19
- raise ArgumentError, "CSV string argument required, such as '3|📕Trying|Lexpub 1970147288'"
19
+ raise ArgumentError, "CSV string argument required, such as '3|📕Trying|Little Library 1970147288'"
20
20
  end
21
21
 
22
22
  config = {}
@@ -63,9 +63,9 @@ module Reading
63
63
 
64
64
  class NotesAttribute < Attribute
65
65
  def parse
66
- return nil unless columns[:public_notes]
66
+ return nil unless columns[:notes]
67
67
 
68
- columns[:public_notes]
68
+ columns[:notes]
69
69
  .presence
70
70
  &.chomp
71
71
  &.remove(/#{config.deep_fetch(:csv, :long_separator).rstrip}\s*\z/)
@@ -133,9 +133,7 @@ module Reading
133
133
  dates_finished
134
134
  genres
135
135
  length
136
- public_notes
137
- blurb
138
- private_notes
136
+ notes
139
137
  history
140
138
  ],
141
139
  # Custom columns are listed in a hash with default values, like simple columns in item[:template] above.
@@ -146,6 +144,8 @@ module Reading
146
144
  separator: ",",
147
145
  short_separator: " - ",
148
146
  long_separator: " -- ",
147
+ date_separator: "/",
148
+ date_range_separator: "..",
149
149
  dnf_string: "DNF",
150
150
  series_prefix: "in",
151
151
  group_emoji: "🤝🏼",
@@ -172,6 +172,7 @@ module Reading
172
172
  time_length = /(?<time>\d+:\d\d)/
173
173
  pages_length = /p?(?<pages>\d+)p?/
174
174
  url = /https?:\/\/[^\s#{@hash.deep_fetch(:csv, :separator)}]+/
175
+ date_sep = @hash.deep_fetch(:csv, :date_separator)
175
176
 
176
177
  isbn_lookbehind = "(?<=\\A|\\s|#{@hash.deep_fetch(:csv, :separator)})"
177
178
  isbn_lookahead = "(?=\\z|\\s|#{@hash.deep_fetch(:csv, :separator)})"
@@ -191,7 +192,7 @@ module Reading
191
192
  progress: /(?<=#{dnf_string}|\A)\s*(?:(?<percent>\d?\d)%|#{time_length}|#{pages_length})\s+/,
192
193
  group_experience: /#{@hash.deep_fetch(:csv, :group_emoji)}\s*(.*)\s*\z/,
193
194
  variant_index: /\s+v(\d+)/,
194
- date: /\d{4}\/\d?\d\/\d?\d/,
195
+ date: /\d{4}#{date_sep}\d?\d#{date_sep}\d?\d/,
195
196
  time_length: /\A#{time_length}(?<each>\s+each)?\z/,
196
197
  time_length_in_variant: time_length,
197
198
  pages_length: /\A#{pages_length}(?<each>\s+each)?\z/,
data/lib/reading/csv.rb CHANGED
@@ -26,17 +26,7 @@ module Reading
26
26
  # @param config [Hash] a custom config which overrides the defaults,
27
27
  # e.g. { errors: { styling: :html } }
28
28
  def initialize(feed = nil, path: nil, config: {})
29
- if feed.nil? && path.nil?
30
- raise ArgumentError, "No file given to load."
31
- end
32
-
33
- if path
34
- if !File.exist?(path)
35
- raise FileError, "File not found! #{@path}"
36
- elsif File.directory?(path)
37
- raise FileError, "The reading log must be a file, but the path given is a directory: #{@path}"
38
- end
39
- end
29
+ validate_feed_or_path(feed, path)
40
30
 
41
31
  @feed = feed
42
32
  @path = path
@@ -63,5 +53,24 @@ module Reading
63
53
  ensure
64
54
  feed&.close if feed.respond_to?(:close)
65
55
  end
56
+
57
+ private
58
+
59
+ # Checks on the given feed and path (arguments to #initialize).
60
+ # @raise [FileError] if the given path is invalid.
61
+ # @raise [ArgumentError] if both feed and path are nil.
62
+ def validate_feed_or_path(feed, path)
63
+ return true if feed
64
+
65
+ if path
66
+ if !File.exist?(path)
67
+ raise FileError, "File not found! #{path}"
68
+ elsif File.directory?(path)
69
+ raise FileError, "The reading log must be a file, but the path given is a directory: #{path}"
70
+ end
71
+ else
72
+ raise ArgumentError, "Either a feed (String, File, etc.) or a file path must be provided."
73
+ end
74
+ end
66
75
  end
67
76
  end
@@ -60,6 +60,9 @@ module Reading
60
60
 
61
61
  # VALIDATION # # # # # # # # # # # # # # # # # # # # # # #
62
62
 
63
+ # Means there are too many columns in a row.
64
+ class TooManyColumnsError < Reading::Error; end
65
+
63
66
  # Means a date is unparsable, or a set of dates does not make logical sense.
64
67
  class InvalidDateError < Reading::Error; end
65
68
 
@@ -57,7 +57,7 @@ module Reading
57
57
 
58
58
  if item_match[:sources_column]
59
59
  if item_match[:sources_column].include?(config.deep_fetch(:csv, :column_separator))
60
- raise InvalidSourceError, "Too many columns (only Sources allowed) " \
60
+ raise TooManyColumnsError, "Too many columns (only Sources allowed) " \
61
61
  "after #{item_head} in compact planned row"
62
62
  end
63
63
 
@@ -62,13 +62,18 @@ module Reading
62
62
  end
63
63
 
64
64
  def set_columns
65
- @columns = (
66
- config.deep_fetch(:csv, :enabled_columns) +
67
- config.deep_fetch(:csv, :custom_numeric_columns).keys +
68
- config.deep_fetch(:csv, :custom_text_columns).keys
69
- )
70
- .zip(string.split(config.deep_fetch(:csv, :column_separator)))
71
- .to_h
65
+ column_names = config.deep_fetch(:csv, :enabled_columns) +
66
+ config.deep_fetch(:csv, :custom_numeric_columns).keys +
67
+ config.deep_fetch(:csv, :custom_text_columns).keys
68
+
69
+ columns_count = string.count(config.deep_fetch(:csv, :column_separator))
70
+ if columns_count >= column_names.count
71
+ raise TooManyColumnsError, "Too many columns"
72
+ end
73
+
74
+ column_contents = string.split(config.deep_fetch(:csv, :column_separator))
75
+
76
+ @columns = column_names.zip(column_contents).to_h
72
77
  end
73
78
 
74
79
  def ensure_head_column_present
@@ -1,3 +1,3 @@
1
1
  module Reading
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reading
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Vogel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-27 00:00:00.000000000 Z
11
+ date: 2023-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel