Class: AocCli::Paths::Day

Inherits:
Object
  • Object
show all
Defined in:
lib/aoc_cli/paths.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(u: Metafile.get(:user), y: Metafile.get(:year), d:) ⇒ Day

Returns a new instance of Day.



31
32
33
34
35
36
# File 'lib/aoc_cli/paths.rb', line 31

def initialize(u:Metafile.get(:user), 
			   y:Metafile.get(:year), d:)
	@user = Validate.user(u)
	@year = Validate.year(y)
	@day  = Validate.day(d)
end

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



30
31
32
# File 'lib/aoc_cli/paths.rb', line 30

def day
  @day
end

#userObject (readonly)

Returns the value of attribute user.



30
31
32
# File 'lib/aoc_cli/paths.rb', line 30

def user
  @user
end

#yearObject (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_dirObject



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_cacheObject



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_dirObject



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

Returns:

  • (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_dirObject



58
59
60
# File 'lib/aoc_cli/paths.rb', line 58

def local_dir
	in_day? ? "." : "#{day_dir}"
end

#prefixObject



40
41
42
# File 'lib/aoc_cli/paths.rb', line 40

def prefix
	Prefs.string(key:"day_dir_prefix")
end