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("\/\.$"),
]

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Returns the value of attribute file_bundle.



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

def file_bundle
  @file_bundle
end

#filesObject



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

#problemObject (readonly)

Returns the value of attribute problem.



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

def problem
  @problem
end

#repoObject (readonly)

Returns the value of attribute repo.



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

def repo
  @repo
end

#rootObject (readonly)

Returns the value of attribute root.



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

def root
  @root
end

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



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

Returns:

  • (Boolean)


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

def exists?
  File.exist?(dir)
end

#git_urlObject



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

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

#readmeObject



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

def readme
  @readme ||= assemble_readme
end

#zipObject



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