Class: SContainer::Subtitle
- Inherits:
-
Object
- Object
- SContainer::Subtitle
- Defined in:
- lib/subtitle.rb
Instance Attribute Summary collapse
-
#cds ⇒ Object
Returns the value of attribute cds.
-
#details ⇒ Object
Returns the value of attribute details.
-
#downloads ⇒ Object
Returns the value of attribute downloads.
-
#movie_title ⇒ Object
Returns the value of attribute movie_title.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#download!(args = {}) ⇒ Object
Downloading the file and saves it disk.
-
#initialize(args) ⇒ Subtitle
constructor
A new instance of Subtitle.
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
#cds ⇒ Object
Returns the value of attribute cds.
6 7 8 |
# File 'lib/subtitle.rb', line 6 def cds @cds end |
#details ⇒ Object
Returns the value of attribute details.
6 7 8 |
# File 'lib/subtitle.rb', line 6 def details @details end |
#downloads ⇒ Object
Returns the value of attribute downloads.
6 7 8 |
# File 'lib/subtitle.rb', line 6 def downloads @downloads end |
#movie_title ⇒ Object
Returns the value of attribute movie_title.
6 7 8 |
# File 'lib/subtitle.rb', line 6 def movie_title @movie_title end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/subtitle.rb', line 6 def title @title end |
#url ⇒ Object
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
17 18 19 20 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 |
# File 'lib/subtitle.rb', line 17 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) rescue nil 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 |