Class: IML::Base
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- IML::Base
- Defined in:
- lib/iml/base.rb
Overview
Base media file class
Instance Attribute Summary collapse
-
#format_string ⇒ String
Allows retrieving and setting of the format string for the output name.
-
#prefix ⇒ String
Allows for setting and getting the output path sans the output base filename.
-
#pretend ⇒ Boolean
Allows for setting and getting dry run setting.
Instance Method Summary collapse
-
#basename ⇒ Pathname
Output base filename.
-
#create_dir ⇒ Array<String>
Creates the output directory if needed.
-
#dirname ⇒ Pathname
Output path sans the output base filename.
- #imdb ⇒ Object
-
#initialize(hash = nil, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#move(path) ⇒ Integer
Moves the media file to the output directory.
-
#pathname ⇒ Pathname
Full output path of the media file.
-
#present ⇒ String
Formated output filename.
Constructor Details
#initialize(hash = nil, options = {}) ⇒ Base
Returns a new instance of Base.
15 16 17 18 19 20 |
# File 'lib/iml/base.rb', line 15 def initialize(hash = nil, = {}) @prefix = [:target] @pretend = [:pretend] super(hash) process if hash end |
Instance Attribute Details
#format_string ⇒ String
Returns Allows retrieving and setting of the format string for the output name.
6 7 8 |
# File 'lib/iml/base.rb', line 6 def format_string @format_string end |
#prefix ⇒ String
Returns Allows for setting and getting the output path sans the output base filename.
8 9 10 |
# File 'lib/iml/base.rb', line 8 def prefix @prefix end |
#pretend ⇒ Boolean
Returns Allows for setting and getting dry run setting.
10 11 12 |
# File 'lib/iml/base.rb', line 10 def pretend @pretend end |
Instance Method Details
#basename ⇒ Pathname
Returns output base filename.
13 |
# File 'lib/iml/base.rb', line 13 delegate :basename, to: :pathname |
#create_dir ⇒ Array<String>
Creates the output directory if needed
43 44 45 |
# File 'lib/iml/base.rb', line 43 def create_dir FileUtils.mkdir_p dirname unless @pretend end |
#dirname ⇒ Pathname
Returns output path sans the output base filename.
12 |
# File 'lib/iml/base.rb', line 12 delegate :dirname, to: :pathname |
#imdb ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/iml/base.rb', line 55 def imdb return nil unless imdb_doc fetch_director fetch_writer fetch_summary fetch_actors self end |
#move(path) ⇒ Integer
Moves the media file to the output directory
49 50 51 52 53 |
# File 'lib/iml/base.rb', line 49 def move(path) FileUtils.mv path, pathname unless @pretend rescue Errno::ENOENT 1 end |
#pathname ⇒ Pathname
Returns full output path of the media file.
32 33 34 |
# File 'lib/iml/base.rb', line 32 def pathname @prefix ? Pathname(@prefix) + Pathname(present) : Pathname(present) end |
#present ⇒ String
Returns formated output filename.
23 24 25 26 27 28 29 |
# File 'lib/iml/base.rb', line 23 def present format_string = output_format self.class::PLACEHOLDERS.each do |placeholder, attribute| format_string = format_string.gsub(placeholder, send(attribute).to_s) end format_string end |