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



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pige/client/chunk.rb', line 26

def download(target)
  target_file = File.join(target, download_file)

  File.open(target_file, "w") do |file|
    open(download_url) do |url|
      IO.copy_stream url, file
    end
  end

  target_file
end

#download_fileObject



22
23
24
# File 'lib/pige/client/chunk.rb', line 22

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

#download_urlObject



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

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

#extensionObject



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

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