plansheet 0.5.1 → 0.7.0

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: 3546f42fdd342ea128be90bff2e19b7bcb5c0910990e2132b89b87cbf6a1f776
4
- data.tar.gz: 2ea5d505262832e19e77a63e7aa7c59c9fff0b98ddc3ee8218c68b010f4768eb
3
+ metadata.gz: 98932ed8f5a5d06da4b2f6135d1321e5376a1af2f837d4a65b9f806c7f06b8d9
4
+ data.tar.gz: 0ef6f026f7bcbc4712d008ca2843a0b5a9d1715038b2fc91534a8c9951697ec6
5
5
  SHA512:
6
- metadata.gz: 335cb1a3e74ab82a1441ec034099427dc0caabaad8a87c1f2620c7143d1fd4772023fe089a7305063fb12a96d169e44dd0b01f8f20437f45bdfa945b03aa2422
7
- data.tar.gz: 5d618d61c6a07d8e32e46cfb4dba5df0264370f01d8b4ecef4c68f9fdcf6fcf600ca33bda0a8918e63992434e2a009e4d836f1f838851e0ee94de53128fe1ab2
6
+ metadata.gz: 95217512c48168c26ef2c5f937dd8b94530bccea1149c2e90df1db039243b9ffb4582efe26ea14ae6393845daa4d8f5a4fec36cff82231d7b6ab6fc6a1255ff6
7
+ data.tar.gz: '095dcda8264517252297a7aba139f8c51bddfbe04880acb9a16d2eb3f4a479003e1ee453902acf65fde2ad89720b522b6d6bd118e3f1f3202f2aab9f9ec50d04'
data/.rubocop.yml CHANGED
@@ -1,3 +1,5 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
1
3
  AllCops:
2
4
  TargetRubyVersion: 2.6
3
5
  NewCops: enable
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,26 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2022-06-02 13:34:43 UTC using RuboCop version 1.29.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: IgnoredMethods.
11
+ Metrics/CyclomaticComplexity:
12
+ Max: 8
13
+
14
+ # Offense count: 1
15
+ # Configuration parameters: IgnoredMethods.
16
+ Metrics/PerceivedComplexity:
17
+ Max: 10
18
+
19
+ # Offense count: 2
20
+ # Configuration parameters: AllowedConstants.
21
+ Style/Documentation:
22
+ Exclude:
23
+ - 'spec/**/*'
24
+ - 'test/**/*'
25
+ - 'lib/plansheet.rb'
26
+ - 'lib/plansheet/project.rb'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plansheet (0.5.1)
4
+ plansheet (0.7.0)
5
5
  dc-kwalify (~> 1.0)
6
6
 
7
7
  GEM
data/exe/plansheet CHANGED
@@ -32,7 +32,7 @@ elsif options[:sort]
32
32
  Plansheet.resort_projects_in_dir config["projects_dir"]
33
33
  elsif options[:cli]
34
34
  project_arr = Plansheet.load_projects_dir config["projects_dir"]
35
- project_arr.each do |proj|
35
+ project_arr.sort.each do |proj|
36
36
  puts proj
37
37
  puts "\n"
38
38
  end
@@ -13,6 +13,12 @@ module Plansheet
13
13
  "done" => 7
14
14
  }.freeze
15
15
 
16
+ PROJECT_PRIORITY = {
17
+ "high" => 1,
18
+ "medium" => 2,
19
+ "low" => 3
20
+ }.freeze
21
+
16
22
  # Once there's some stability in plansheet and dc-kwalify, will pre-load this
17
23
  # to save the later YAML.load
18
24
  PROJECT_YAML_SCHEMA = <<~YAML
@@ -25,6 +31,13 @@ module Plansheet
25
31
  desc: Project name
26
32
  type: str
27
33
  required: yes
34
+ "priority":
35
+ desc: Project priority
36
+ type: str
37
+ enum:
38
+ - high
39
+ - medium
40
+ - low
28
41
  "status":
29
42
  desc: The current status of the project
30
43
  type: str
@@ -38,15 +51,22 @@ module Plansheet
38
51
  # want to keep around for reference, etc
39
52
  - done # project is finished, but want to keep around
40
53
  # for reference, etc.
41
- "priority":
42
- desc: Project priority (not currently implemented)
43
- type: str
44
- enum:
45
- - high
46
- - low
47
54
  "location":
48
- desc: Location (not currently implemented)
55
+ desc: Location
49
56
  type: str
57
+ "notes":
58
+ desc: Free-form notes string
59
+ type: str
60
+ "externals":
61
+ desc: List of external commitments, ie who else cares about project completion?
62
+ type: seq
63
+ sequence:
64
+ - type: str
65
+ "urls":
66
+ desc: List of URLs that may be pertinent
67
+ type: seq
68
+ sequence:
69
+ - type: str
50
70
  "tasks":
51
71
  desc: List of tasks to do
52
72
  type: seq
@@ -57,30 +77,60 @@ module Plansheet
57
77
  type: seq
58
78
  sequence:
59
79
  - type: str
60
- "notes":
61
- desc: Free-form notes string
62
- type: str
63
80
  YAML
64
81
  PROJECT_SCHEMA = YAML.safe_load(PROJECT_YAML_SCHEMA)
82
+
83
+ # The use of instance_variable_set/get probably seems a bit weird, but the
84
+ # intent is to avoid object allocation on non-existent project properties, as
85
+ # well as avoiding a bunch of copy-paste boilerplate when adding a new
86
+ # property. I suspect I'm guilty of premature optimization here, but it's
87
+ # easier to do this at the start than untangle that later (ie easier to
88
+ # unwrap the loops if it's not needed.
65
89
  class Project
66
- attr_reader :name, :tasks, :done, :notes, :location
90
+ include Comparable
91
+
92
+ # NOTE: The order of these affects presentation!
93
+ STRING_PROPERTIES = %w[priority status location notes].freeze
94
+ ARRAY_PROPERTIES = %w[externals urls tasks done].freeze
95
+
96
+ ALL_PROPERTIES = STRING_PROPERTIES + ARRAY_PROPERTIES
97
+
98
+ attr_reader :name, *ALL_PROPERTIES
67
99
 
68
100
  def initialize(options)
69
101
  @name = options["project"]
70
102
 
71
- @tasks = options["tasks"] || []
72
- @done = options["done"] || []
103
+ ALL_PROPERTIES.each do |o|
104
+ instance_variable_set("@#{o}", options[o]) if options[o]
105
+ end
106
+
107
+ # The "priority" concept feels flawed - it requires *me* to figure out
108
+ # the priority, as opposed to the program understanding the project in
109
+ # relation to other tasks. If I truly understood the priority of all the
110
+ # projects, I wouldn't need a todo list program. The point is to remove
111
+ # the need for willpower/executive function/coffee. The long-term value
112
+ # of this field will diminish as I add more project properties that can
113
+ # automatically hone in on the most important items based on due
114
+ # date/external commits/penalties for project failure, etc
115
+ #
116
+ # Assume all projects are low priority unless stated otherwise.
117
+ @priority ||= "low"
118
+ end
73
119
 
74
- @notes = options["notes"] if options["notes"]
75
- @location = options["location"] if options["location"]
76
- @status = options["status"] if options["status"]
120
+ def <=>(other)
121
+ if @priority == other.priority
122
+ # TODO: if planning status, then sort based on tasks? category? alphabetically?
123
+ PROJECT_STATUS_PRIORITY[status] <=> PROJECT_STATUS_PRIORITY[other.status]
124
+ else
125
+ PROJECT_PRIORITY[@priority] <=> PROJECT_PRIORITY[other.priority]
126
+ end
77
127
  end
78
128
 
79
129
  def status
80
130
  return @status if @status
81
131
 
82
- if @tasks.count.positive?
83
- if @done.count.positive?
132
+ if @tasks&.count&.positive?
133
+ if @done&.count&.positive?
84
134
  "wip"
85
135
  else
86
136
  "planning"
@@ -92,27 +142,42 @@ module Plansheet
92
142
 
93
143
  def to_s
94
144
  str = String.new
95
- str << "# #{@name}\n"
96
- str << "status: #{status}\n"
97
- str << "notes: #{notes}\n" unless @notes.nil?
98
- str << "location: #{location}\n" unless @location.nil?
99
- str << "tasks:\n" unless @tasks.empty?
100
- @tasks.each do |t|
101
- str << "- #{t}\n"
145
+ str << "# #{@name}\n"
146
+ STRING_PROPERTIES.each do |o|
147
+ str << stringify_string_property(o)
148
+ end
149
+ ARRAY_PROPERTIES.each do |o|
150
+ str << stringify_array_property(o)
151
+ end
152
+ str
153
+ end
154
+
155
+ def stringify_string_property(prop)
156
+ if instance_variable_defined? "@#{prop}"
157
+ "#{prop}: #{instance_variable_get("@#{prop}")}\n"
158
+ else
159
+ ""
102
160
  end
103
- str << "done:\n" unless @done.empty?
104
- @done.each do |d|
105
- str << "- #{d}\n"
161
+ end
162
+
163
+ def stringify_array_property(prop)
164
+ str = String.new
165
+ if instance_variable_defined? "@#{prop}"
166
+ str << "#{prop}:\n"
167
+ instance_variable_get("@#{prop}").each do |t|
168
+ str << "- #{t}\n"
169
+ end
106
170
  end
107
171
  str
108
172
  end
173
+
109
174
  def to_h
110
175
  h = { "project" => @name }
111
- h["status"] = status unless status == "idea"
112
- h["notes"] = @notes unless @notes.nil?
113
- h["location"] = @location unless @location.nil?
114
- h["tasks"] = @tasks unless @tasks.empty?
115
- h["done"] = @done unless @done.empty?
176
+ ALL_PROPERTIES.each do |prop|
177
+ h[prop] = instance_variable_get("@#{prop}") if instance_variable_defined?("@#{prop}")
178
+ end
179
+ h.delete "priority" if h.key?("priority") && h["priority"] == "low"
180
+ h.delete "status" if h.key?("status") && h["status"] == "idea"
116
181
  h
117
182
  end
118
183
  end
@@ -132,17 +197,15 @@ module Plansheet
132
197
  validator = Kwalify::Validator.new(Plansheet::PROJECT_SCHEMA)
133
198
  errors = validator.validate(@raw)
134
199
  # Check YAML validity
135
- if errors && !errors.empty?
136
- $stderr.write "Schema errors in #{l}\n"
137
- errors.each { |err| puts "- [#{err.path}] #{err.message}" }
138
- abort
139
- end
200
+ return unless errors && !errors.empty?
201
+
202
+ $stderr.write "Schema errors in #{@path}:\n"
203
+ errors.each { |err| puts "- [#{err.path}] #{err.message}" }
204
+ abort
140
205
  end
141
206
 
142
207
  def sort!
143
- @projects.sort_by! do |project|
144
- Plansheet::PROJECT_STATUS_PRIORITY[project.status]
145
- end
208
+ @projects.sort!
146
209
  end
147
210
 
148
211
  def yaml_dump
@@ -5,9 +5,7 @@ module Plansheet
5
5
  # The Sheet class constructs a Markdown/LaTeX file for use with pandoc
6
6
  class Sheet
7
7
  def initialize(output_file, project_arr)
8
- sorted_arr = project_arr.sort_by do |p|
9
- Plansheet::PROJECT_STATUS_PRIORITY[p.status]
10
- end
8
+ sorted_arr = project_arr.sort!
11
9
 
12
10
  projects_str = String.new
13
11
  projects_str << sheet_header
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plansheet
4
- VERSION = "0.5.1"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plansheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Crosby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-31 00:00:00.000000000 Z
11
+ date: 2022-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dc-kwalify
@@ -33,6 +33,7 @@ extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
35
  - ".rubocop.yml"
36
+ - ".rubocop_todo.yml"
36
37
  - CODE_OF_CONDUCT.md
37
38
  - Gemfile
38
39
  - Gemfile.lock