aoc_cli 0.2.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.rubocop.yml +88 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +8 -0
  6. data/Gemfile.lock +187 -0
  7. data/README.md +88 -282
  8. data/Rakefile +9 -2
  9. data/Steepfile +13 -0
  10. data/aoc_cli.gemspec +36 -26
  11. data/db/migrate/1_create_events.rb +14 -0
  12. data/db/migrate/2_create_puzzles.rb +21 -0
  13. data/db/migrate/3_create_stats.rb +19 -0
  14. data/db/migrate/4_create_attempts.rb +19 -0
  15. data/db/migrate/5_create_locations.rb +17 -0
  16. data/db/migrate/6_create_puzzle_dir_sync_logs.rb +18 -0
  17. data/exe/aoc +5 -0
  18. data/lib/aoc_cli/components/attempts_table.erb +5 -0
  19. data/lib/aoc_cli/components/attempts_table.rb +58 -0
  20. data/lib/aoc_cli/components/docs_component.erb +19 -0
  21. data/lib/aoc_cli/components/docs_component.rb +41 -0
  22. data/lib/aoc_cli/components/errors_component.erb +8 -0
  23. data/lib/aoc_cli/components/errors_component.rb +36 -0
  24. data/lib/aoc_cli/components/progress_table.erb +1 -0
  25. data/lib/aoc_cli/components/progress_table.rb +43 -0
  26. data/lib/aoc_cli/components/puzzle_sync_component.erb +2 -0
  27. data/lib/aoc_cli/components/puzzle_sync_component.rb +26 -0
  28. data/lib/aoc_cli/configurators/session_configurator.rb +7 -0
  29. data/lib/aoc_cli/controllers/application_controller.rb +27 -0
  30. data/lib/aoc_cli/controllers/concerns/error_concern.rb +17 -0
  31. data/lib/aoc_cli/controllers/concerns/location_concern.rb +79 -0
  32. data/lib/aoc_cli/controllers/default_controller.rb +9 -0
  33. data/lib/aoc_cli/controllers/event_controller.rb +35 -0
  34. data/lib/aoc_cli/controllers/help/event_controller.rb +11 -0
  35. data/lib/aoc_cli/controllers/help/puzzle_controller.rb +13 -0
  36. data/lib/aoc_cli/controllers/puzzle_controller.rb +39 -0
  37. data/lib/aoc_cli/core/attempt_parser.rb +69 -0
  38. data/lib/aoc_cli/core/processor.rb +32 -0
  39. data/lib/aoc_cli/core/repository.rb +74 -0
  40. data/lib/aoc_cli/core/request.rb +37 -0
  41. data/lib/aoc_cli/core/resource.rb +39 -0
  42. data/lib/aoc_cli/core/stats_parser.rb +43 -0
  43. data/lib/aoc_cli/helpers/table_generator.rb +64 -0
  44. data/lib/aoc_cli/helpers/view_helper.rb +35 -0
  45. data/lib/aoc_cli/models/attempt.rb +67 -0
  46. data/lib/aoc_cli/models/event.rb +9 -0
  47. data/lib/aoc_cli/models/location.rb +24 -0
  48. data/lib/aoc_cli/models/puzzle.rb +28 -0
  49. data/lib/aoc_cli/models/puzzle_dir_sync_log.rb +14 -0
  50. data/lib/aoc_cli/models/stats.rb +43 -0
  51. data/lib/aoc_cli/presenters/attempt_presenter.rb +29 -0
  52. data/lib/aoc_cli/presenters/puzzle_presenter.rb +29 -0
  53. data/lib/aoc_cli/presenters/stats_presenter.rb +32 -0
  54. data/lib/aoc_cli/processors/event_initialiser.rb +64 -0
  55. data/lib/aoc_cli/processors/puzzle_dir_synchroniser.rb +80 -0
  56. data/lib/aoc_cli/processors/puzzle_initialiser.rb +91 -0
  57. data/lib/aoc_cli/processors/puzzle_refresher.rb +27 -0
  58. data/lib/aoc_cli/processors/resource_attacher.rb +22 -0
  59. data/lib/aoc_cli/processors/solution_poster.rb +72 -0
  60. data/lib/aoc_cli/processors/stats_initialiser.rb +36 -0
  61. data/lib/aoc_cli/processors/stats_refresher.rb +23 -0
  62. data/lib/aoc_cli/validators/collection_type_validator.rb +57 -0
  63. data/lib/aoc_cli/validators/event_year_validator.rb +42 -0
  64. data/lib/aoc_cli/validators/included_validator.rb +21 -0
  65. data/lib/aoc_cli/validators/integer_validator.rb +32 -0
  66. data/lib/aoc_cli/validators/path_validator.rb +39 -0
  67. data/lib/aoc_cli/validators/type_validator.rb +54 -0
  68. data/lib/aoc_cli/version.rb +1 -1
  69. data/lib/aoc_cli/views/event/attach.erb +3 -0
  70. data/lib/aoc_cli/views/event/init.erb +3 -0
  71. data/lib/aoc_cli/views/help/event/attach.erb +32 -0
  72. data/lib/aoc_cli/views/help/event/init.erb +38 -0
  73. data/lib/aoc_cli/views/help/event/progress.erb +12 -0
  74. data/lib/aoc_cli/views/help/puzzle/attempts.erb +12 -0
  75. data/lib/aoc_cli/views/help/puzzle/init.erb +31 -0
  76. data/lib/aoc_cli/views/help/puzzle/solve.erb +33 -0
  77. data/lib/aoc_cli/views/help/puzzle/sync.erb +32 -0
  78. data/lib/aoc_cli/views/puzzle/init.erb +3 -0
  79. data/lib/aoc_cli/views/puzzle/solve.erb +10 -0
  80. data/lib/aoc_cli.rb +32 -16
  81. data/rbs_collection.lock.yaml +168 -0
  82. data/rbs_collection.yaml +28 -0
  83. data/sig/aoc_cli/components/attempts_table.rbs +29 -0
  84. data/sig/aoc_cli/components/docs_component.rbs +15 -0
  85. data/sig/aoc_cli/components/errors_component.rbs +19 -0
  86. data/sig/aoc_cli/components/progress_table.rbs +28 -0
  87. data/sig/aoc_cli/components/puzzle_sync_component.rbs +19 -0
  88. data/sig/aoc_cli/configurators/session_configurator.rbs +7 -0
  89. data/sig/aoc_cli/controllers/application_controller.rbs +12 -0
  90. data/sig/aoc_cli/controllers/concerns/error_concern.rbs +9 -0
  91. data/sig/aoc_cli/controllers/concerns/location_concern.rbs +35 -0
  92. data/sig/aoc_cli/controllers/default_controller.rbs +7 -0
  93. data/sig/aoc_cli/controllers/event_controller.rbs +18 -0
  94. data/sig/aoc_cli/controllers/help/event_controller.rbs +11 -0
  95. data/sig/aoc_cli/controllers/help/puzzle_controller.rbs +13 -0
  96. data/sig/aoc_cli/controllers/puzzle_controller.rbs +15 -0
  97. data/sig/aoc_cli/core/attempt_parser.rbs +41 -0
  98. data/sig/aoc_cli/core/processor.rbs +25 -0
  99. data/sig/aoc_cli/core/repository.rbs +25 -0
  100. data/sig/aoc_cli/core/request.rbs +29 -0
  101. data/sig/aoc_cli/core/resource.rbs +25 -0
  102. data/sig/aoc_cli/core/stats_parser.rbs +23 -0
  103. data/sig/aoc_cli/helpers/table_generator.rbs +36 -0
  104. data/sig/aoc_cli/helpers/view_helper.rbs +15 -0
  105. data/sig/aoc_cli/models/attempt.rbs +35 -0
  106. data/sig/aoc_cli/models/event.rbs +17 -0
  107. data/sig/aoc_cli/models/location.rbs +19 -0
  108. data/sig/aoc_cli/models/puzzle.rbs +28 -0
  109. data/sig/aoc_cli/models/puzzle_dir_sync_log.rbs +11 -0
  110. data/sig/aoc_cli/models/stats.rbs +53 -0
  111. data/sig/aoc_cli/presenters/attempt_presenter.rbs +13 -0
  112. data/sig/aoc_cli/presenters/puzzle_presenter.rbs +19 -0
  113. data/sig/aoc_cli/presenters/stats_presenter.rbs +19 -0
  114. data/sig/aoc_cli/processors/event_initialiser.rbs +26 -0
  115. data/sig/aoc_cli/processors/puzzle_dir_synchroniser.rbs +40 -0
  116. data/sig/aoc_cli/processors/puzzle_initialiser.rbs +37 -0
  117. data/sig/aoc_cli/processors/puzzle_refresher.rbs +21 -0
  118. data/sig/aoc_cli/processors/resource_attacher.rbs +16 -0
  119. data/sig/aoc_cli/processors/solution_poster.rbs +34 -0
  120. data/sig/aoc_cli/processors/stats_initialiser.rbs +15 -0
  121. data/sig/aoc_cli/processors/stats_refresher.rbs +19 -0
  122. data/sig/aoc_cli/validators/collection_type_validator.rbs +24 -0
  123. data/sig/aoc_cli/validators/event_year_validator.rbs +19 -0
  124. data/sig/aoc_cli/validators/included_validator.rbs +11 -0
  125. data/sig/aoc_cli/validators/integer_validator.rbs +15 -0
  126. data/sig/aoc_cli/validators/path_validator.rbs +17 -0
  127. data/sig/aoc_cli/validators/type_validator.rbs +22 -0
  128. data/sig/aoc_cli.rbs +6 -0
  129. data/sig/http.rbs +3 -0
  130. data/sig/kangaru.rbs +5 -0
  131. data/sig/nokogiri.rbs +3 -0
  132. data/sig/reverse_markdown.rbs +3 -0
  133. metadata +142 -34
  134. data/.gitignore +0 -5
  135. data/bin/aoc +0 -4
  136. data/bin/console +0 -15
  137. data/bin/setup +0 -7
  138. data/lib/aoc_cli/commands.rb +0 -232
  139. data/lib/aoc_cli/database.rb +0 -224
  140. data/lib/aoc_cli/day.rb +0 -124
  141. data/lib/aoc_cli/db/reddit.db +0 -0
  142. data/lib/aoc_cli/errors.rb +0 -275
  143. data/lib/aoc_cli/files.rb +0 -163
  144. data/lib/aoc_cli/help.rb +0 -77
  145. data/lib/aoc_cli/interface.rb +0 -81
  146. data/lib/aoc_cli/paths.rb +0 -101
  147. data/lib/aoc_cli/solve.rb +0 -104
  148. data/lib/aoc_cli/tables.rb +0 -138
  149. data/lib/aoc_cli/tools.rb +0 -120
  150. data/lib/aoc_cli/year.rb +0 -116
  151. data/sample/aoc.rc +0 -21
data/lib/aoc_cli/tools.rb DELETED
@@ -1,120 +0,0 @@
1
- module AocCli
2
- module Tools
3
- class Request
4
- require 'curb'
5
- attr_reader :user, :year, :day, :base, :page, :ua
6
- def initialize(u:Metafile.get(:user),
7
- y:Metafile.get(:year),
8
- d:Metafile.get(:day), p:)
9
- @user = Validate.user(u)
10
- @year = Validate.year(y)
11
- @day = d
12
- @page = p
13
- @base = "https://adventofcode.com/#{year}"
14
- @ua = "github.com/apexatoll/aoc-cli"
15
- end
16
- protected
17
- def get
18
- Curl.get(url) do |h|
19
- h.headers['Cookie'] = cookie
20
- h.headers['User-Agent'] = ua
21
- end.body
22
- end
23
- def post(data:)
24
- Curl.post(url, data) do |h|
25
- h.headers['Cookie'] = cookie
26
- h.headers['User-Agent'] = ua
27
- end.body
28
- end
29
- private
30
- def cookie
31
- Files::Config::Cookie.key(user:user)
32
- end
33
- def url
34
- case page.to_sym
35
- when :Calendar then base
36
- when :Stats then base + "/leaderboard/self"
37
- when :Puzzle then base + "/day/#{day}"
38
- when :Input then base + "/day/#{day}/input"
39
- when :Answer then base + "/day/#{day}/answer"
40
- end
41
- end
42
- end
43
- class Convert < Request
44
- require 'pandoc-ruby'
45
- attr_accessor :input
46
- def array
47
- input.split("\n")
48
- end
49
- def chunk(f:, t:, t_off:0, f_off:0)
50
- pt1 = array.index {|l| l =~ /#{f}/} + t_off
51
- pt2 = array.rindex{|l| l =~ /#{t}/} + f_off
52
- @input = array.slice(pt1, pt2 - pt1).join("\n")
53
- self
54
- end
55
- def raw
56
- input.split("\n").join("\n")
57
- end
58
- def plain
59
- PandocRuby.new(input, f: html, t: :plain).convert
60
- end
61
- def md
62
- PandocRuby.new(input, {f: html, t: :gfm},
63
- md_head, md_ref).convert
64
- end
65
- private
66
- def html
67
- "html-native_divs-native_spans"
68
- end
69
- def md_head
70
- "--markdown-headings=setext"
71
- end
72
- def md_ref
73
- "--reference-links"
74
- end
75
- end
76
- class Get < Convert
77
- def initialize(u:Metafile.get(:user),
78
- y:Metafile.get(:year), d:nil, p:)
79
- @input = Request.new(u:u, y:y, d:d, p:p).get
80
- end
81
- end
82
- class Post < Convert
83
- def initialize(u:Metafile.get(:user),
84
- y:Metafile.get(:year),
85
- d:Metafile.get(:day),
86
- p:"Answer", data:)
87
- @input = Request
88
- .new(u:u, y:y, d:d, p:p)
89
- .post(data:data)
90
- end
91
- end
92
- class Reddit
93
- attr_reader :year, :day, :uniq, :browser
94
- def initialize(y:Metafile.get(:year),
95
- d:Metafile.get(:day),
96
- b:Prefs.bool(key:"reddit_in_browser"))
97
- @year = Validate.year(y)
98
- @day = Validate.day(d)
99
- @uniq = Database::Query
100
- .new(path:Paths::Database.root("reddit"))
101
- .select(t:"'#{year}'", where:{day:"'#{day}'"})
102
- .flatten[1]
103
- @browser = b
104
- end
105
- def open
106
- system("#{browser ? "open" : cmd} #{link}")
107
- end
108
- def cmd
109
- ["ttrv", "rtv"]
110
- .map{|cli| cli unless `which #{cli}`.empty?}
111
- .reject{|cmd| cmd.nil?}&.first || "open"
112
- end
113
- def link
114
- "https://www.reddit.com/r/"\
115
- "adventofcode/comments/#{uniq}/"\
116
- "#{year}_day_#{day}_solutions"
117
- end
118
- end
119
- end
120
- end
data/lib/aoc_cli/year.rb DELETED
@@ -1,116 +0,0 @@
1
- module AocCli
2
- module Year
3
- def self.refresh
4
- puts "- Updating calendar...".blue
5
- Year::Meta.new.write
6
- Year::Progress.new.write
7
- .init_calendar_db
8
- end
9
- class Meta
10
- attr_reader :user, :year, :paths
11
- def initialize(u:Prefs.default_alias,
12
- y:Metafile.get(:year))
13
- @user = Validate.user(u)
14
- @year = Validate.year(y)
15
- @paths = Paths::Year.new(u:user, y:year)
16
- end
17
- def write
18
- File.write(paths.local(f:"meta"),
19
- Metafile.year(u:user, y:year))
20
- end
21
- end
22
- class Progress < Meta
23
- def stats
24
- @stats ||= Requests::Stats.new(u:user, y:year)
25
- end
26
- def cal
27
- @cal ||= Requests::Calendar.new(u:user, y:year)
28
- .fill(stars:stats.stars)
29
- end
30
- def file
31
- Files::Calendar.new(stats:stats, cal:cal).make
32
- end
33
- def write?
34
- Prefs.bool(key:"calendar_file")
35
- end
36
- def write
37
- File.write(paths.local(f:"Stars"), file) if write?
38
- self
39
- end
40
- def init_calendar_db
41
- Database::Calendar::Init
42
- .new(u:user, y:year, stars:stats.stars)
43
- .insert
44
- end
45
- end
46
- module Requests
47
- class Request < Meta
48
- attr_reader :data
49
- def initialize(u:Metafile.get(:user),
50
- y:Metafile.get(:year))
51
- super(u:u, y:y)
52
- @data = parse(raw: fetch)
53
- end
54
- private
55
- def fetch
56
- Tools::Get.new(u:user, y:year, p:page)
57
- .plain.split("\n")
58
- end
59
- end
60
- class Calendar < Request
61
- def page
62
- :Calendar
63
- end
64
- def parse(raw:)
65
- raw.drop(raw.index{|l| l =~ /\*\*/})
66
- .map{|l| l.gsub(/\*\*/, "")}
67
- end
68
- def fill(stars:)
69
- stars.each{|s, n| data.each{|l| l
70
- .gsub!(/(^.*)\b#{s}\b.$/, "\\1#{s}\s#{"*" * n}")}}
71
- self
72
- end
73
- end
74
- class Stats < Request
75
- def page
76
- :Stats
77
- end
78
- def parse(raw:)
79
- /You haven't collected/.match?(raw.to_s) ?
80
- raw : raw.drop(raw.index{|l| l =~ /^.*Part 1/})
81
- end
82
- def stars
83
- data.map{|l| l.scan(/^\s+\d+/)&.first}
84
- .reject{|s| s == nil}
85
- .map{|s| [s.to_i, data
86
- .grep(/^.*#{s}.*(\-.*){3}$/)
87
- .count == 0 ? 2 : 1]}.to_h
88
- end
89
- def total_stars
90
- stars.values.reduce(:+).to_i || 0
91
- end
92
- end
93
- end
94
- class GitWrap
95
- require 'git'
96
- attr_reader :git
97
- def initialize
98
- @git = Git.init
99
- File.write(".gitignore", ignore)
100
- git.add(".gitignore")
101
- end
102
- def ignore_md?
103
- Prefs.bool(key:"ignore_md_files")
104
- end
105
- def ignore_meta?
106
- Prefs.bool(key:"ignore_meta_files")
107
- end
108
- def ignore
109
- <<~ignore
110
- #{".meta\n**/.meta" if ignore_meta?}#{
111
- "\n*.md\n**/*.md" if ignore_md?}
112
- ignore
113
- end
114
- end
115
- end
116
- end
data/sample/aoc.rc DELETED
@@ -1,21 +0,0 @@
1
- //aoc-cli example config
2
- //See the github repo for more information on configuring aoc-cli
3
- //https://github.com/apexatoll/aoc-cli
4
-
5
- [General]
6
- //Print table in unicode rather than ascii
7
- unicode_tables=>true
8
- //Open Reddit in browser rather than use a Reddit CLI
9
- reddit_in_browser=>false
10
-
11
- [Initialise Year]
12
- //Create a calendar file
13
- calendar_file=>true
14
- //Initialise git repo on year initialisation
15
- init_git=>false
16
- //Add calendar and puzzle files to gitignore
17
- ignore_md_files=>true
18
- //Add .meta files to gitignore
19
- ignore_meta_files=>true
20
- //Include leaderboard stats in calendar file
21
- lb_in_calendar=>true