Class: Trackler::Implementation
- Inherits:
-
Object
- Object
- Trackler::Implementation
- Defined in:
- lib/trackler/implementation.rb
Overview
Implementation is a language-specific implementation of an exercise.
Constant Summary collapse
- IGNORE =
[ Regexp.new("HINTS\.md$"), Regexp.new("example", Regexp::IGNORECASE), Regexp.new("\/\.$"), Regexp.new("/\.meta/") ]
Instance Attribute Summary collapse
-
#file_bundle ⇒ Object
readonly
Returns the value of attribute file_bundle.
- #files ⇒ Object
-
#problem ⇒ Object
readonly
Returns the value of attribute problem.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#track_id ⇒ Object
readonly
Returns the value of attribute track_id.
Instance Method Summary collapse
- #exercise_dir ⇒ Object
- #exists? ⇒ Boolean
- #git_url ⇒ Object
-
#initialize(track_id, repo, problem, root) ⇒ Implementation
constructor
A new instance of Implementation.
- #readme ⇒ Object
- #zip ⇒ Object
Constructor Details
#initialize(track_id, repo, problem, root) ⇒ Implementation
Returns a new instance of Implementation.
16 17 18 19 20 21 22 |
# File 'lib/trackler/implementation.rb', line 16 def initialize(track_id, repo, problem, root) @track_id = track_id @repo = repo @problem = problem @root = Pathname.new(root) @file_bundle = FileBundle.new(track_directory, IGNORE) end |
Instance Attribute Details
#file_bundle ⇒ Object (readonly)
Returns the value of attribute file_bundle.
14 15 16 |
# File 'lib/trackler/implementation.rb', line 14 def file_bundle @file_bundle end |
#files ⇒ Object
28 29 30 31 32 |
# File 'lib/trackler/implementation.rb', line 28 def files @files ||= Hash[file_bundle.paths.map {|path| [path.relative_path_from(track_directory).to_s, File.read(path)] }].merge("README.md" => readme) end |
#problem ⇒ Object (readonly)
Returns the value of attribute problem.
14 15 16 |
# File 'lib/trackler/implementation.rb', line 14 def problem @problem end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
14 15 16 |
# File 'lib/trackler/implementation.rb', line 14 def repo @repo end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
14 15 16 |
# File 'lib/trackler/implementation.rb', line 14 def root @root end |
#track_id ⇒ Object (readonly)
Returns the value of attribute track_id.
14 15 16 |
# File 'lib/trackler/implementation.rb', line 14 def track_id @track_id end |
Instance Method Details
#exercise_dir ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/trackler/implementation.rb', line 45 def exercise_dir if File.exist?(track_dir.join('exercises')) File.join('exercises', problem.slug) else problem.slug end end |
#exists? ⇒ Boolean
24 25 26 |
# File 'lib/trackler/implementation.rb', line 24 def exists? File.exist?(track_directory) end |
#git_url ⇒ Object
53 54 55 |
# File 'lib/trackler/implementation.rb', line 53 def git_url [repo, "tree/master", exercise_dir].join("/") end |
#readme ⇒ Object
41 42 43 |
# File 'lib/trackler/implementation.rb', line 41 def readme @readme ||= assemble_readme end |
#zip ⇒ Object
34 35 36 37 38 39 |
# File 'lib/trackler/implementation.rb', line 34 def zip @zip ||= file_bundle.zip do |io| io.put_next_entry('README.md') io.print readme end end |