Class: Trackler::Implementation

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_bundleObject (readonly)

Returns the value of attribute file_bundle.



14
15
16
# File 'lib/trackler/implementation.rb', line 14

def file_bundle
  @file_bundle
end

#filesObject



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

#problemObject (readonly)

Returns the value of attribute problem.



14
15
16
# File 'lib/trackler/implementation.rb', line 14

def problem
  @problem
end

#repoObject (readonly)

Returns the value of attribute repo.



14
15
16
# File 'lib/trackler/implementation.rb', line 14

def repo
  @repo
end

#rootObject (readonly)

Returns the value of attribute root.



14
15
16
# File 'lib/trackler/implementation.rb', line 14

def root
  @root
end

#track_idObject (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_dirObject



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

Returns:

  • (Boolean)


24
25
26
# File 'lib/trackler/implementation.rb', line 24

def exists?
  File.exist?(track_directory)
end

#git_urlObject



53
54
55
# File 'lib/trackler/implementation.rb', line 53

def git_url
  [repo, "tree/master", exercise_dir].join("/")
end

#readmeObject



41
42
43
# File 'lib/trackler/implementation.rb', line 41

def readme
  @readme ||= assemble_readme
end

#zipObject



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