reading 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/bin/reading +80 -10
  3. data/lib/reading/config.rb +27 -5
  4. data/lib/reading/errors.rb +4 -1
  5. data/lib/reading/item/time_length.rb +60 -23
  6. data/lib/reading/item/view.rb +14 -19
  7. data/lib/reading/item.rb +321 -54
  8. data/lib/reading/parsing/attributes/attribute.rb +0 -7
  9. data/lib/reading/parsing/attributes/experiences/dates_and_head_transformer.rb +10 -11
  10. data/lib/reading/parsing/attributes/experiences/history_transformer.rb +27 -18
  11. data/lib/reading/parsing/attributes/experiences/spans_validator.rb +18 -19
  12. data/lib/reading/parsing/attributes/experiences.rb +5 -5
  13. data/lib/reading/parsing/attributes/shared.rb +13 -6
  14. data/lib/reading/parsing/attributes/variants.rb +9 -6
  15. data/lib/reading/parsing/csv.rb +38 -35
  16. data/lib/reading/parsing/parser.rb +23 -24
  17. data/lib/reading/parsing/rows/blank.rb +23 -0
  18. data/lib/reading/parsing/rows/comment.rb +6 -7
  19. data/lib/reading/parsing/rows/compact_planned.rb +9 -9
  20. data/lib/reading/parsing/rows/compact_planned_columns/head.rb +2 -2
  21. data/lib/reading/parsing/rows/custom_config.rb +42 -0
  22. data/lib/reading/parsing/rows/regular.rb +15 -14
  23. data/lib/reading/parsing/rows/regular_columns/length.rb +8 -8
  24. data/lib/reading/parsing/rows/regular_columns/sources.rb +15 -9
  25. data/lib/reading/parsing/transformer.rb +13 -17
  26. data/lib/reading/stats/filter.rb +738 -0
  27. data/lib/reading/stats/grouping.rb +243 -0
  28. data/lib/reading/stats/operation.rb +313 -0
  29. data/lib/reading/stats/query.rb +37 -0
  30. data/lib/reading/stats/terminal_result_formatters.rb +91 -0
  31. data/lib/reading/util/exclude.rb +12 -0
  32. data/lib/reading/util/hash_to_data.rb +2 -2
  33. data/lib/reading/version.rb +1 -1
  34. data/lib/reading.rb +36 -21
  35. metadata +10 -6
  36. data/bin/readingfile +0 -31
  37. data/lib/reading/util/string_remove.rb +0 -28
  38. data/lib/reading/util/string_truncate.rb +0 -22
@@ -1,3 +1,3 @@
1
1
  module Reading
2
- VERSION = "0.8.0"
2
+ VERSION = '0.9.0'
3
3
  end
data/lib/reading.rb CHANGED
@@ -1,26 +1,36 @@
1
- require_relative "reading/parsing/csv"
2
- require_relative "reading/filter"
3
- require_relative "reading/config"
4
- require_relative "reading/item/time_length.rb"
1
+ Dir[File.join(__dir__, 'reading', 'util', '*.rb')].each { |file| require file }
2
+ require_relative 'reading/errors'
3
+ require_relative 'reading/config'
4
+ require_relative 'reading/parsing/csv'
5
+ require_relative 'reading/filter'
6
+ require_relative 'reading/stats/query'
7
+ require_relative 'reading/item/time_length.rb'
5
8
 
6
9
  # The gem's public API. See https://github.com/fpsvogel/reading#usage
7
10
  #
8
11
  # Architectural overview:
9
12
  #
10
- # (CSV input) (Items) (filtered Items)
11
- # | Λ | Λ
12
- # | | ·---. |
13
- # | | | |
14
- # V | V |
15
- # ::parse | ::filter |
16
- # | | | |
17
- # | .----------> Item Filter
18
- # Config, | / / \
19
- # errors.rb ----- Parsing::CSV --· Item::View Item::TimeLength
20
- # / \
21
- # Parsing::Parser Parsing::Transformer
22
- # | |
23
- # parsing/attributes/* parsing/rows/*
13
+ # (filtered (stats input*
14
+ # (CSV input) (Items) Items) and Items) (results)
15
+ # | Λ | Λ | Λ
16
+ # V | V | V |
17
+ # ::parse | ::filter | ::stats |
18
+ # | | | | | |
19
+ # | | | | | |
20
+ # | | | | | |
21
+ # Parsing::CSV ---------> Item Filter Stats::Query
22
+ # / \ / \ / | \
23
+ # / \ Item::View Item::TimeLength / | \
24
+ # / \ / | \
25
+ # Parsing::Parser Parsing::Transformer Stats::Filter | Stats::Operation
26
+ # | | Stats::Grouping
27
+ # parsing/rows/* parsing/attributes/*
28
+ # * Stats input is either from the
29
+ # command line (via the `reading`
30
+ # command) or provided via Ruby
31
+ # code that uses this gem.
32
+ # Results likewise go either to
33
+ # stdout or to the gem user.
24
34
  #
25
35
  module Reading
26
36
  # Parses a CSV file or string. See Parsing::CSV#initialize and #parse for details.
@@ -34,10 +44,15 @@ module Reading
34
44
  Filter.by(...)
35
45
  end
36
46
 
37
- # The default config.
47
+ # Returns statistics on Items. See Stats::Query#initialize and #result for details.
48
+ def self.stats(...)
49
+ query = Stats::Query.new(...)
50
+ query.result
51
+ end
52
+
38
53
  # @return [Hash]
39
- def self.default_config
40
- Config.new.hash
54
+ def self.config
55
+ Config.hash
41
56
  end
42
57
 
43
58
  # A shortcut for getting a time from a string.
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.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Vogel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-12 00:00:00.000000000 Z
11
+ date: 2023-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -127,12 +127,10 @@ email:
127
127
  - fps.vogel@gmail.com
128
128
  executables:
129
129
  - reading
130
- - readingfile
131
130
  extensions: []
132
131
  extra_rdoc_files: []
133
132
  files:
134
133
  - bin/reading
135
- - bin/readingfile
136
134
  - lib/reading.rb
137
135
  - lib/reading/config.rb
138
136
  - lib/reading/errors.rb
@@ -154,10 +152,12 @@ files:
154
152
  - lib/reading/parsing/attributes/variants.rb
155
153
  - lib/reading/parsing/csv.rb
156
154
  - lib/reading/parsing/parser.rb
155
+ - lib/reading/parsing/rows/blank.rb
157
156
  - lib/reading/parsing/rows/column.rb
158
157
  - lib/reading/parsing/rows/comment.rb
159
158
  - lib/reading/parsing/rows/compact_planned.rb
160
159
  - lib/reading/parsing/rows/compact_planned_columns/head.rb
160
+ - lib/reading/parsing/rows/custom_config.rb
161
161
  - lib/reading/parsing/rows/regular.rb
162
162
  - lib/reading/parsing/rows/regular_columns/end_dates.rb
163
163
  - lib/reading/parsing/rows/regular_columns/genres.rb
@@ -169,14 +169,18 @@ files:
169
169
  - lib/reading/parsing/rows/regular_columns/sources.rb
170
170
  - lib/reading/parsing/rows/regular_columns/start_dates.rb
171
171
  - lib/reading/parsing/transformer.rb
172
+ - lib/reading/stats/filter.rb
173
+ - lib/reading/stats/grouping.rb
174
+ - lib/reading/stats/operation.rb
175
+ - lib/reading/stats/query.rb
176
+ - lib/reading/stats/terminal_result_formatters.rb
172
177
  - lib/reading/util/blank.rb
178
+ - lib/reading/util/exclude.rb
173
179
  - lib/reading/util/hash_array_deep_fetch.rb
174
180
  - lib/reading/util/hash_compact_by_template.rb
175
181
  - lib/reading/util/hash_deep_merge.rb
176
182
  - lib/reading/util/hash_to_data.rb
177
183
  - lib/reading/util/numeric_to_i_if_whole.rb
178
- - lib/reading/util/string_remove.rb
179
- - lib/reading/util/string_truncate.rb
180
184
  - lib/reading/version.rb
181
185
  homepage: https://github.com/fpsvogel/reading
182
186
  licenses:
data/bin/readingfile DELETED
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # A script that provides a quick way to see the output of a CSV file.
4
- #
5
- # Usage:
6
- # Run on the command line:
7
- # reading "<file path>" "<optional comma-separated names of enabled columns>"
8
- #
9
- # Examples:
10
- # reading '/home/felipe/reading.csv'
11
- # reading '/home/felipe/reading.csv' 'head, sources'
12
-
13
-
14
- require_relative "../lib/reading"
15
- require "amazing_print"
16
- require "debug"
17
-
18
- path = ARGV[0]
19
- unless path
20
- raise ArgumentError, "CSV path argument required, such as '/home/felipe/reading.csv'"
21
- end
22
-
23
- config = {}
24
- if ARGV[1]
25
- enabled_columns = ARGV[1].split(",").map(&:strip).map(&:to_sym)
26
- config = { enabled_columns: }
27
- end
28
-
29
- items = Reading.parse(path, config:, hash_output: true)
30
-
31
- ap items
@@ -1,28 +0,0 @@
1
- module Reading
2
- module Util
3
- # Shortcuts for String#sub and String#gsub when replacing with an empty string.
4
- module StringRemove
5
- refine String do
6
- def remove(pattern)
7
- sub(pattern, EMPTY_STRING)
8
- end
9
-
10
- def remove!(pattern)
11
- sub!(pattern, EMPTY_STRING)
12
- end
13
-
14
- def remove_all(pattern)
15
- gsub(pattern, EMPTY_STRING)
16
- end
17
-
18
- def remove_all!(pattern)
19
- gsub!(pattern, EMPTY_STRING)
20
- end
21
- end
22
-
23
- private
24
-
25
- EMPTY_STRING = "".freeze
26
- end
27
- end
28
- end
@@ -1,22 +0,0 @@
1
- module Reading
2
- module Util
3
- # Shortens the String to a given length.
4
- module StringTruncate
5
- refine String do
6
- # @param length [Integer]
7
- # @return [String]
8
- def truncate(length)
9
- if length < self.length - ELLIPSIS.length
10
- "#{self[0...length]}#{ELLIPSIS}"
11
- else
12
- self
13
- end
14
- end
15
- end
16
-
17
- private
18
-
19
- ELLIPSIS = "...".freeze
20
- end
21
- end
22
- end