Class: Comet::Challenge
- Inherits:
-
Object
- Object
- Comet::Challenge
- Defined in:
- lib/comet/challenge.rb
Instance Attribute Summary collapse
-
#basedir ⇒ Object
readonly
Returns the value of attribute basedir.
-
#download_link ⇒ Object
readonly
Returns the value of attribute download_link.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Class Method Summary collapse
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize(params) ⇒ Challenge
constructor
A new instance of Challenge.
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
#basedir ⇒ Object (readonly)
Returns the value of attribute basedir.
4 5 6 |
# File 'lib/comet/challenge.rb', line 4 def basedir @basedir end |
#download_link ⇒ Object (readonly)
Returns the value of attribute download_link.
4 5 6 |
# File 'lib/comet/challenge.rb', line 4 def download_link @download_link end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/comet/challenge.rb', line 4 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/comet/challenge.rb', line 4 def name @name end |
#slug ⇒ Object (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
#download ⇒ Object
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 |