Class: Exercism::Assignment
- Inherits:
-
Object
- Object
- Exercism::Assignment
- Defined in:
- lib/exercism/assignment.rb
Instance Attribute Summary collapse
-
#project_dir ⇒ Object
readonly
Returns the value of attribute project_dir.
-
#readme ⇒ Object
readonly
Returns the value of attribute readme.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#test_file ⇒ Object
readonly
Returns the value of attribute test_file.
-
#tests ⇒ Object
readonly
Returns the value of attribute tests.
-
#track ⇒ Object
readonly
Returns the value of attribute track.
Class Method Summary collapse
Instance Method Summary collapse
- #assignment_dir ⇒ Object
- #exercise ⇒ Object
-
#initialize(attributes) ⇒ Assignment
constructor
A new instance of Assignment.
- #save ⇒ Object
- #save_readme ⇒ Object
- #save_tests ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Assignment
Returns a new instance of Assignment.
12 13 14 15 16 17 18 19 |
# File 'lib/exercism/assignment.rb', line 12 def initialize(attributes) @track = attributes['track'] @slug = attributes['slug'] @readme = attributes['readme'] @test_file = attributes['test_file'] @tests = attributes['tests'] @project_dir = attributes['project_dir'] end |
Instance Attribute Details
#project_dir ⇒ Object (readonly)
Returns the value of attribute project_dir.
10 11 12 |
# File 'lib/exercism/assignment.rb', line 10 def project_dir @project_dir end |
#readme ⇒ Object (readonly)
Returns the value of attribute readme.
10 11 12 |
# File 'lib/exercism/assignment.rb', line 10 def readme @readme end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
10 11 12 |
# File 'lib/exercism/assignment.rb', line 10 def slug @slug end |
#test_file ⇒ Object (readonly)
Returns the value of attribute test_file.
10 11 12 |
# File 'lib/exercism/assignment.rb', line 10 def test_file @test_file end |
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
10 11 12 |
# File 'lib/exercism/assignment.rb', line 10 def tests @tests end |
#track ⇒ Object (readonly)
Returns the value of attribute track.
10 11 12 |
# File 'lib/exercism/assignment.rb', line 10 def track @track end |
Class Method Details
.save(data, path) ⇒ Object
4 5 6 7 8 |
# File 'lib/exercism/assignment.rb', line 4 def self.save(data, path) data['assignments'].map do |attributes| new(attributes.merge('project_dir' => path)).save end end |
Instance Method Details
#assignment_dir ⇒ Object
44 45 46 |
# File 'lib/exercism/assignment.rb', line 44 def assignment_dir @assignment_dir ||= File.join(project_dir, track, slug) end |
#exercise ⇒ Object
21 22 23 |
# File 'lib/exercism/assignment.rb', line 21 def exercise File.join(track, slug) end |
#save ⇒ Object
25 26 27 28 29 30 |
# File 'lib/exercism/assignment.rb', line 25 def save FileUtils.mkdir_p assignment_dir save_readme save_tests unless File.exist?(tests_path) self end |
#save_readme ⇒ Object
32 33 34 35 36 |
# File 'lib/exercism/assignment.rb', line 32 def save_readme File.open readme_path, 'w' do |f| f.write readme end end |
#save_tests ⇒ Object
38 39 40 41 42 |
# File 'lib/exercism/assignment.rb', line 38 def save_tests File.open tests_path, 'w' do |f| f.write tests end end |