Class: Trackler::Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/trackler/problem.rb

Overview

Problem is a language-independent definition of an exercise.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slug, root) ⇒ Problem

Returns a new instance of Problem.



7
8
9
10
# File 'lib/trackler/problem.rb', line 7

def initialize(slug, root)
  @slug = slug
  @root = root
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



6
7
8
# File 'lib/trackler/problem.rb', line 6

def root
  @root
end

#slugObject (readonly)

Returns the value of attribute slug.



6
7
8
# File 'lib/trackler/problem.rb', line 6

def slug
  @slug
end

Instance Method Details

#descriptionObject



20
21
22
# File 'lib/trackler/problem.rb', line 20

def description
  @description ||= File.read(filepath(md))
end

#exists?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/trackler/problem.rb', line 12

def exists?
  !!md && !!yaml
end

#json_urlObject



38
39
40
# File 'lib/trackler/problem.rb', line 38

def json_url
  repo_url(json) if !!json
end

#md_urlObject



34
35
36
# File 'lib/trackler/problem.rb', line 34

def md_url
  repo_url(md)
end

#nameObject



16
17
18
# File 'lib/trackler/problem.rb', line 16

def name
  @name ||= slug.split('-').map(&:capitalize).join(' ')
end

#source_markdownObject



24
25
26
27
28
29
30
31
32
# File 'lib/trackler/problem.rb', line 24

def source_markdown
  body = source.empty? ? "" : "%s" % source
  url = source_url.empty? ? "" : "[%s](%s)" % [source_url, source_url]
  if url.empty? && body.empty?
    ""
  else
    "## Source\n\n" + [body, url].reject(&:empty?).join(" ")
  end
end

#yaml_urlObject



42
43
44
# File 'lib/trackler/problem.rb', line 42

def yaml_url
  repo_url(yaml)
end