Class: Comet::Challenge

Inherits:
Object
  • Object
show all
Defined in:
lib/comet/challenge.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Challenge

Returns a new instance of Challenge.



6
7
8
9
10
11
12
# File 'lib/comet/challenge.rb', line 6

def initialize(params)
  @id = params[:id]
  @name = params[:name]
  @slug = params[:slug]
  @download_link = params[:download_link]
  @basedir = params[:basedir]
end

Instance Attribute Details

#basedirObject (readonly)

Returns the value of attribute basedir.



4
5
6
# File 'lib/comet/challenge.rb', line 4

def basedir
  @basedir
end

Returns the value of attribute download_link.



4
5
6
# File 'lib/comet/challenge.rb', line 4

def download_link
  @download_link
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/comet/challenge.rb', line 4

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/comet/challenge.rb', line 4

def name
  @name
end

#slugObject (readonly)

Returns the value of attribute slug.



4
5
6
# File 'lib/comet/challenge.rb', line 4

def slug
  @slug
end

Class Method Details

.find(config, id) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/comet/challenge.rb', line 26

def find(config, id)
  challenge_info = Comet::API.get_challenge(config, id)

  if challenge_info.nil?
    raise ArgumentError.new("Could not find challenge with id = #{id}")
  else
    Comet::Challenge.new(challenge_info.merge({ basedir: config['basedir'] }))
  end
end

.list(config) ⇒ Object



22
23
24
# File 'lib/comet/challenge.rb', line 22

def list(config)
  Comet::API.get_challenges(config)
end

Instance Method Details

#downloadObject



14
15
16
17
18
19
# File 'lib/comet/challenge.rb', line 14

def download
  archive = Comet::API.download_archive(download_link, File.join(basedir, "#{slug}.tar.gz"))
  `tar zxf #{Shellwords.escape(archive)} -C #{Shellwords.escape(basedir)}`
  File.delete(archive)
  File.join(basedir, slug)
end