Class: AocCli::Paths::Day
- Inherits:
-
Object
- Object
- AocCli::Paths::Day
- Defined in:
- lib/aoc_cli/paths.rb
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #cache_and_local(f:) ⇒ Object
- #cache_dir ⇒ Object
- #cache_path(f:) ⇒ Object
- #create_cache ⇒ Object
- #day_dir ⇒ Object
- #filename(f:) ⇒ Object
- #in_day? ⇒ Boolean
-
#initialize(u: Metafile.get(:user), y: Metafile.get(:year), d:) ⇒ Day
constructor
A new instance of Day.
- #local(f:) ⇒ Object
- #local_dir ⇒ Object
- #prefix ⇒ Object
Constructor Details
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
30 31 32 |
# File 'lib/aoc_cli/paths.rb', line 30 def day @day end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
30 31 32 |
# File 'lib/aoc_cli/paths.rb', line 30 def user @user end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
30 31 32 |
# File 'lib/aoc_cli/paths.rb', line 30 def year @year end |
Instance Method Details
#cache_and_local(f:) ⇒ Object
71 72 73 |
# File 'lib/aoc_cli/paths.rb', line 71 def cache_and_local(f:) [cache_path(f:f), local(f:f)] end |
#cache_dir ⇒ Object
61 62 63 64 |
# File 'lib/aoc_cli/paths.rb', line 61 def cache_dir "#{Dir.home}/.cache/aoc-cli/"\ "#{user}/#{year}/#{day_dir}" end |
#cache_path(f:) ⇒ Object
68 69 70 |
# File 'lib/aoc_cli/paths.rb', line 68 def cache_path(f:) "#{cache_dir}/#{filename(f:f)}" end |
#create_cache ⇒ Object
37 38 39 |
# File 'lib/aoc_cli/paths.rb', line 37 def create_cache FileUtils.mkdir_p(cache_dir) unless Dir.exist?(cache_dir) end |
#day_dir ⇒ Object
53 54 55 56 57 |
# File 'lib/aoc_cli/paths.rb', line 53 def day_dir day.to_i < 10 ? "#{prefix}0#{day}" : "#{prefix}#{day}" end |
#filename(f:) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/aoc_cli/paths.rb', line 43 def filename(f:) case f.to_sym when :Input then "input" when :Puzzle then "#{day}.md" when :meta then ".meta" end end |
#in_day? ⇒ Boolean
50 51 52 |
# File 'lib/aoc_cli/paths.rb', line 50 def in_day? Metafile.type == :DAY end |
#local(f:) ⇒ Object
65 66 67 |
# File 'lib/aoc_cli/paths.rb', line 65 def local(f:) "#{local_dir}/#{filename(f:f)}" end |
#local_dir ⇒ Object
58 59 60 |
# File 'lib/aoc_cli/paths.rb', line 58 def local_dir in_day? ? "." : "#{day_dir}" end |
#prefix ⇒ Object
40 41 42 |
# File 'lib/aoc_cli/paths.rb', line 40 def prefix Prefs.string(key:"day_dir_prefix") end |