Class: AocCli::Files::Calendar

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(y: Metafile.get(:year), cal:, stats:) ⇒ Calendar

Returns a new instance of Calendar.



140
141
142
# File 'lib/aoc_cli/files.rb', line 140

def initialize(y:Metafile.get(:year), cal:, stats:)
	@year, @cal, @stats  = Validate.year(y), cal, stats
end

Instance Attribute Details

#calObject (readonly)

Returns the value of attribute cal.



139
140
141
# File 'lib/aoc_cli/files.rb', line 139

def cal
  @cal
end

#statsObject (readonly)

Returns the value of attribute stats.



139
140
141
# File 'lib/aoc_cli/files.rb', line 139

def stats
  @stats
end

#yearObject (readonly)

Returns the value of attribute year.



139
140
141
# File 'lib/aoc_cli/files.rb', line 139

def year
  @year
end

Instance Method Details

#include_leaderboard?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/aoc_cli/files.rb', line 143

def include_leaderboard?
	Prefs.bool(key:"lb_in_calendar")
end

#makeObject



152
153
154
155
156
157
158
159
160
# File 'lib/aoc_cli/files.rb', line 152

def make
	<<~file
		#{title}
		#{underline}
		#{cal.data.join("\n")}\n
		#{stats.data.join("\n") if stats.total_stars > 0 &&
			include_leaderboard?}
	file
end

#titleObject



146
147
148
# File 'lib/aoc_cli/files.rb', line 146

def title
	"Year #{year}: #{stats.total_stars}/50 *"
end

#underlineObject



149
150
151
# File 'lib/aoc_cli/files.rb', line 149

def underline
	"-" * (cal.data[0].to_s.length + 2)
end