class Commands::Track::Exercise
Attributes
name[R]
path[R]
track[R]
Public Class Methods
new(track:, name:, path:)
click to toggle source
# File lib/commands/track/exercise.rb, line 6 def initialize(track:, name:, path:) @track = track @name = name @path = path end
Public Instance Methods
==(other)
click to toggle source
# File lib/commands/track/exercise.rb, line 23 def ==(other) name == other.name && path == other.path end
detail()
click to toggle source
# File lib/commands/track/exercise.rb, line 12 def detail "#{preamble}[Click here](../tree/master/#{path}) to read the #{name} exercise" end
name_error_msg()
click to toggle source
# File lib/commands/track/exercise.rb, line 31 def name_error_msg 'Name not given for exercise' end
path_error_msg()
click to toggle source
# File lib/commands/track/exercise.rb, line 27 def path_error_msg "Exercise: #{name} - not found at path: #{path}" end
validate()
click to toggle source
# File lib/commands/track/exercise.rb, line 16 def validate raise ArgumentError, name_error_msg unless name raise ArgumentError, path_error_msg unless File.exist?(path) true end
Private Instance Methods
preamble()
click to toggle source
# File lib/commands/track/exercise.rb, line 37 def preamble return '' unless File.exist?(preamble_path) "#{File.read(preamble_path)}\n" end
preamble_path()
click to toggle source
# File lib/commands/track/exercise.rb, line 43 def preamble_path "#{track}/#{to_snake_case(name)}.md" end
to_snake_case(string)
click to toggle source
# File lib/commands/track/exercise.rb, line 47 def to_snake_case(string) string.downcase.gsub(/\s+/, '_') end