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, track = NullTrack.new) ⇒ Problem

Returns a new instance of Problem.



10
11
12
13
14
15
16
17
18
# File 'lib/trackler/problem.rb', line 10

def initialize(slug, root, track = NullTrack.new)
  @slug = slug
  @root = root
  @file_root = File.join(root, 'common', 'exercises', self.slug)
  @repo_root = "https://github.com/exercism/x-common/blob/master/exercises/%s/" % self.slug

  @metadata = Metadata.for(problem: self, track: track)
  self.description_object = Description.for(problem: self, track: track)
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



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

def 
  @metadata
end

#rootObject (readonly)

Returns the value of attribute root.



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

def root
  @root
end

#slugObject (readonly)

Returns the value of attribute slug.



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

def slug
  @slug
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/trackler/problem.rb', line 28

def active?
  exists? && !deprecated?
end

#blurbObject



78
79
80
# File 'lib/trackler/problem.rb', line 78

def blurb
  .blurb
end

#canonical_data_urlObject



70
71
72
# File 'lib/trackler/problem.rb', line 70

def canonical_data_url
  repo_url(canonical_data_file_name) if File.exists?(file_path(canonical_data_file_name, @file_root))
end

#deprecated?Boolean

Returns:

  • (Boolean)


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

def deprecated?
  @deprecated ||= File.exists?(file_path(deprecation_file_name, @file_root))
end

#descriptionObject



36
37
38
# File 'lib/trackler/problem.rb', line 36

def description
  description_object.to_s
end

#description_urlObject

End deprecated methods



66
67
68
# File 'lib/trackler/problem.rb', line 66

def description_url
  description_object.url
end

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  description_object.exists? && .exists?
end

#json_urlObject



56
57
58
# File 'lib/trackler/problem.rb', line 56

def json_url
  canonical_data_url
end

#md_urlObject

Deprecated methods TODO: remove external references to these methods. found in: x-api NOT in: exercism.io, cli Anywhere else we need to look? Should this output a warning or raise an error?



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

def md_url
  description_url
end

#metadata_urlObject



74
75
76
# File 'lib/trackler/problem.rb', line 74

def 
  .url
end

#nameObject



32
33
34
# File 'lib/trackler/problem.rb', line 32

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

#sourceObject



82
83
84
# File 'lib/trackler/problem.rb', line 82

def source
  .source
end

#source_markdownObject



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

def source_markdown
  text = [source, markdown_link(source_url)].reject(&:empty?).join(" ")
  text.empty? ? text : "## Source\n\n#{text}"
end

#source_urlObject



86
87
88
# File 'lib/trackler/problem.rb', line 86

def source_url
  .source_url
end

#yaml_urlObject



60
61
62
# File 'lib/trackler/problem.rb', line 60

def yaml_url
  
end