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



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



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

def format_string
  @format_string
end

#prefixString



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

def prefix
  @prefix
end

#pretendBoolean



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

def pretend
  @pretend
end

Instance Method Details

#basenamePathname



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
# => ["."]


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

def create_dir
  FileUtils.mkdir_p dirname unless @pretend
end

#dirnamePathname



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

delegate :dirname, to: :pathname

#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

#pathnamePathname



32
33
34
# File 'lib/iml/base.rb', line 32

def pathname
  @prefix ? Pathname(@prefix) + Pathname(present) : Pathname(present)
end

#presentString



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