Class: Commands::Track::Exercise

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/track/exercise.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(track:, name:, path:) ⇒ Exercise

Returns a new instance of Exercise.



6
7
8
9
10
# File 'lib/commands/track/exercise.rb', line 6

def initialize(track:, name:, path:)
  @track = track
  @name = name
  @path = path
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/commands/track/exercise.rb', line 4

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/commands/track/exercise.rb', line 4

def path
  @path
end

#trackObject (readonly)

Returns the value of attribute track.



4
5
6
# File 'lib/commands/track/exercise.rb', line 4

def track
  @track
end

Instance Method Details

#==(other) ⇒ Object



23
24
25
# File 'lib/commands/track/exercise.rb', line 23

def ==(other)
  name == other.name && path == other.path
end

#detailObject



12
13
14
# File 'lib/commands/track/exercise.rb', line 12

def detail
  "#{preamble}[Click here](../tree/master/#{path}) to read the #{name} exercise"
end

#name_error_msgObject



31
32
33
# File 'lib/commands/track/exercise.rb', line 31

def name_error_msg
  'Name not given for exercise'
end

#path_error_msgObject



27
28
29
# File 'lib/commands/track/exercise.rb', line 27

def path_error_msg
  "Exercise: #{name} - not found at path: #{path}"
end

#validateObject

Raises:

  • (ArgumentError)


16
17
18
19
20
21
# 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