Class: IML::Base

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/iml/base.rb

Overview

Base media file class

Direct Known Subclasses

Movie, TVSeries

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @prefix = options[:target]
  @pretend = options[:pretend]
  super(hash)
  process if hash
end

Instance Attribute Details

#format_stringString

Returns Allows retrieving and setting of the format string for the output name.

Returns:

  • (String)

    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

#prefixString

Returns Allows for setting and getting the output path sans the output base filename.

Returns:

  • (String)

    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

#pretendBoolean

Returns Allows for setting and getting dry run setting.

Returns:

  • (Boolean)

    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

#basenamePathname

Returns output base filename.

Returns:

  • (Pathname)

    output base filename



13
# File 'lib/iml/base.rb', line 13

delegate :basename, to: :pathname

#create_dirArray<String>

Creates the output directory if needed

Examples:

movie = IML::Text.new('Cool.Movie.2018.720p.BluRay.H264.AAC2.0-GROUP.mp4').detect
# => <IML::Movie title="Cool Movie", year="2018", quality="720p", source="BluRay" ..>
movie.create_dir
# => ["."]

Returns:

  • (Array<String>)

    array containing the path of the created output directory



43
44
45
# File 'lib/iml/base.rb', line 43

def create_dir
  FileUtils.mkdir_p dirname unless @pretend
end

#dirnamePathname

Returns output path sans the output base filename.

Returns:

  • (Pathname)

    output path sans the output base filename



12
# File 'lib/iml/base.rb', line 12

delegate :dirname, to: :pathname

#imdbObject



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_rating
  fetch_writer
  fetch_summary
  fetch_actors
  self
end

#move(path) ⇒ Integer

Moves the media file to the output directory

Returns:

  • (Integer)

    0 on success, 1 on failure



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

#pathnamePathname

Returns full output path of the media file.

Returns:

  • (Pathname)

    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

#presentString

Returns formated output filename.

Returns:

  • (String)

    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