Class: Woody::Episode

Inherits:
Post
  • Object
show all
Defined in:
lib/woody/episode.rb

Overview

Represents an episode of the podcast. Inherits from Post.

Instance Attribute Summary collapse

Attributes inherited from Post

#compiledname, #date, #filename, #raw_body, #subtitle, #tags, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Post

#<=>, #body, #keywords, #path, #path!, #url

Constructor Details

#initialize(site, filename, title, date, raw_body, subtitle = nil, tags = [], explicit = false) ⇒ Episode

Creates a new Episode object

Parameters:

  • filename (String)

    specifies the name of the MP3 file

  • title (String)

    specifies the episode’s title

  • date (Date)

    specifies the episode’s published date

  • body (String)

    specifies the episode’s synopsis/body

  • subtitle (String) (defaults to: nil)

    specifies the episode’s subtitle

  • tags (Array) (defaults to: [])

    specifies the episode’s tags - each element is a String



22
23
24
25
26
# File 'lib/woody/episode.rb', line 22

def initialize(site, filename, title, date, raw_body, subtitle = nil, tags = [], explicit = false)
  super site, filename, title, subtitle, raw_body, date, tags
  @explicit = explicit
  @compiledname = @filename.gsub(/[^0-9A-Za-z ._]/, '').gsub(' ', '_')
end

Instance Attribute Details

#explicitObject

Returns the value of attribute explicit.



28
29
30
# File 'lib/woody/episode.rb', line 28

def explicit
  @explicit
end

Class Method Details

.new_from_meta(site, filename, meta) ⇒ Episode

Creates a new Episode object from segment of metadata.yml

Parameters:

  • filename (String)

    specifies the name of the MP3 file

  • meta (Hash)

    is the relevant part of metadata.yml

Returns:

  • (Episode)

    the new Episode object



10
11
12
# File 'lib/woody/episode.rb', line 10

def self.new_from_meta(site, filename, meta)
  return Episode.new(site, filename, meta['title'], Date.parse(meta['date'].to_s), meta['synopsis'], meta['subtitle'], meta['tags'], meta['explicit'])
end

Instance Method Details

#durationString

Returns the duration of the media file, formatted as minutes:seconds.

Returns:

  • (String)

    the duration of the media file, formatted as minutes:seconds



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/woody/episode.rb', line 63

def duration
  return @duration unless @duration.nil?
  length = 0
  Mp3Info.open(@site.dir(File.join("content", filename))) do |mp3|
    length = mp3.length
  end
  @duration = Time.at(length).gmtime.strftime('%R:%S') # Should work up to 24 hours
  if @duration.start_with? "00:"
    @duration = @duration[3..-1]
  end
end

#explicit_stringString

Returns ‘yes’ if explicit content, otherwise ‘no’.

Returns:

  • (String)

    ‘yes’ if explicit content, otherwise ‘no’



58
59
60
# File 'lib/woody/episode.rb', line 58

def explicit_string 
  @explicit ? 'yes' : 'no'
end

#file_path(leader = true) ⇒ Object

Returns the episode’s media file path! where possible, otherwise false. Includes site prefix if enabled.

Returns:

  • the episode’s media file path! where possible, otherwise false. Includes site prefix if enabled.



44
45
46
47
48
# File 'lib/woody/episode.rb', line 44

def file_path(leader=true)
  prefix = @site.config['s3']['prefix']
  return "#{leader ? "/" : ""}#{prefix.nil? ? "" : prefix + "/" }assets/mp3/#{@compiledname}" unless @compiledname.nil?
  return false
end

#file_path!(leader = true) ⇒ Object

Returns the episode’s media file path! where possible, otherwise false. Does not take prefix in to account.

Returns:

  • the episode’s media file path! where possible, otherwise false. Does not take prefix in to account.



38
39
40
41
# File 'lib/woody/episode.rb', line 38

def file_path!(leader=true)
  return "#{leader ? "/" : ""}assets/mp3/#{@compiledname}" unless @compiledname.nil?
  return false
end

#file_urlObject

Returns the episode’s media file URL where possible, otherwise false.

Returns:

  • the episode’s media file URL where possible, otherwise false



32
33
34
35
# File 'lib/woody/episode.rb', line 32

def file_url
  return "#{@site.config['urlbase']}#{file_path!}" unless file_path! == false
  return false
end

#has_file?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/woody/episode.rb', line 76

def has_file?
  true
end

#sizeInteger

Returns the size of the episodes media file in bytes.

Returns:

  • (Integer)

    the size of the episodes media file in bytes



53
54
55
# File 'lib/woody/episode.rb', line 53

def size
  File.size @site.dir(File.join("content", filename))
end