Class: SContainer::Subtitle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Subtitle

Returns a new instance of Subtitle.



8
9
10
# File 'lib/subtitle.rb', line 8

def initialize(args)
  args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] }
end

Instance Attribute Details

#cdsObject

Returns the value of attribute cds.



6
7
8
# File 'lib/subtitle.rb', line 6

def cds
  @cds
end

#detailsObject

Returns the value of attribute details.



6
7
8
# File 'lib/subtitle.rb', line 6

def details
  @details
end

#downloadsObject

Returns the value of attribute downloads.



6
7
8
# File 'lib/subtitle.rb', line 6

def downloads
  @downloads
end

#movie_titleObject

Returns the value of attribute movie_title.



6
7
8
# File 'lib/subtitle.rb', line 6

def movie_title
  @movie_title
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/subtitle.rb', line 6

def title
  @title
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/subtitle.rb', line 6

def url
  @url
end

Instance Method Details

#download!(args = {}) ⇒ Object

Downloading the file and saves it disk



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/subtitle.rb', line 21

def download!(args = {})
  if args[:to].nil?
    dir = "/tmp"
    file_name = "#{dir}/#{generate_file_name}"
  else
    dir = generate_custom_file_path(args)
    file_name = "#{dir}/#{generate_file_name}"
  end

  data = RestClient.get(self.url, :timeout => 10)
  file = File.new(file_name, 'w')
  file.write(data)
  file.close

  type = Mimer.identify(file_name)

  if type.zip?
    file_ending = ".zip"
  elsif type.rar?
    file_ending = ".rar"
  else
    file_ending = ""
  end

  new_file_name = "#{dir}/#{title.gsub(/\s+/, '.')}#{file_ending}"

  # Changing the name on the file
  FileUtils.mv(file_name, new_file_name)

  # I like return :)
  return new_file_name
end