Class: Pige::Client::Chunk

Inherits:
Resource show all
Defined in:
lib/pige/client/chunk.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#created_at, #errors, #id, #source_id, #updated_at

Instance Method Summary collapse

Methods inherited from Resource

all, base_url, create, #destroy, destroy, destroy_all, #initialize, older_than, #older_than?, resource_name, resources_name, time_attribute

Constructor Details

This class inherits a constructor from Pige::Client::Resource

Instance Attribute Details

#beginObject

Returns the value of attribute begin.



4
5
6
# File 'lib/pige/client/chunk.rb', line 4

def begin
  @begin
end

#completion_rateObject

Returns the value of attribute completion_rate.



4
5
6
# File 'lib/pige/client/chunk.rb', line 4

def completion_rate
  @completion_rate
end

#endObject

Returns the value of attribute end.



4
5
6
# File 'lib/pige/client/chunk.rb', line 4

def end
  @end
end

#formatObject

Returns the value of attribute format.



4
5
6
# File 'lib/pige/client/chunk.rb', line 4

def format
  @format
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/pige/client/chunk.rb', line 4

def title
  @title
end

Instance Method Details

#download(target) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/pige/client/chunk.rb', line 23

def download(target)
  File.open(File.join(target, download_file), "w") do |file|
    open(download_url) do |url|
      IO.copy_stream url, file
    end
  end
end

#download_fileObject



19
20
21
# File 'lib/pige/client/chunk.rb', line 19

def download_file
  "#{title}.#{extension}"
end

#download_urlObject



15
16
17
# File 'lib/pige/client/chunk.rb', line 15

def download_url
  "#{Pige::Client.box_url}/sources/1/chunks/#{id}.#{extension}"
end

#extensionObject



11
12
13
# File 'lib/pige/client/chunk.rb', line 11

def extension
  format == "vorbis" ? "ogg" : format
end