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.



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

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.



2
3
4
# File 'lib/comet/challenge.rb', line 2

def basedir
  @basedir
end

Returns the value of attribute download_link.



2
3
4
# File 'lib/comet/challenge.rb', line 2

def download_link
  @download_link
end

#idObject (readonly)

Returns the value of attribute id.



2
3
4
# File 'lib/comet/challenge.rb', line 2

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/comet/challenge.rb', line 2

def name
  @name
end

#slugObject (readonly)

Returns the value of attribute slug.



2
3
4
# File 'lib/comet/challenge.rb', line 2

def slug
  @slug
end

Class Method Details

.find(config, id) ⇒ Object



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

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



20
21
22
# File 'lib/comet/challenge.rb', line 20

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

Instance Method Details

#downloadObject



12
13
14
15
16
17
# File 'lib/comet/challenge.rb', line 12

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