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("\/\.$"), ]
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.
15 16 17 18 19 20 21 |
# File 'lib/trackler/implementation.rb', line 15 def initialize(track_id, repo, problem, root) @track_id = track_id @repo = repo @problem = problem @root = Pathname.new(root) @file_bundle = FileBundle.new(dir, IGNORE) end |
Instance Attribute Details
#file_bundle ⇒ Object (readonly)
Returns the value of attribute file_bundle.
13 14 15 |
# File 'lib/trackler/implementation.rb', line 13 def file_bundle @file_bundle end |
#files ⇒ Object
27 28 29 30 31 |
# File 'lib/trackler/implementation.rb', line 27 def files @files ||= Hash[file_bundle.paths.map {|path| [path.relative_path_from(dir).to_s, File.read(path)] }].merge("README.md" => readme) end |
#problem ⇒ Object (readonly)
Returns the value of attribute problem.
13 14 15 |
# File 'lib/trackler/implementation.rb', line 13 def problem @problem end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
13 14 15 |
# File 'lib/trackler/implementation.rb', line 13 def repo @repo end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
13 14 15 |
# File 'lib/trackler/implementation.rb', line 13 def root @root end |
#track_id ⇒ Object (readonly)
Returns the value of attribute track_id.
13 14 15 |
# File 'lib/trackler/implementation.rb', line 13 def track_id @track_id end |
Instance Method Details
#exercise_dir ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/trackler/implementation.rb', line 44 def exercise_dir if File.exist?(track_dir.join('exercises')) File.join('exercises', problem.slug) else problem.slug end end |
#exists? ⇒ Boolean
23 24 25 |
# File 'lib/trackler/implementation.rb', line 23 def exists? File.exist?(dir) end |
#git_url ⇒ Object
52 53 54 |
# File 'lib/trackler/implementation.rb', line 52 def git_url [repo, "tree/master", exercise_dir].join("/") end |
#readme ⇒ Object
40 41 42 |
# File 'lib/trackler/implementation.rb', line 40 def readme @readme ||= assemble_readme end |
#zip ⇒ Object
33 34 35 36 37 38 |
# File 'lib/trackler/implementation.rb', line 33 def zip @zip ||= file_bundle.zip do |io| io.put_next_entry('README.md') io.print readme end end |