Class: Woody::Episode

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

Overview

Represents an episode of the podcast

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, title, date, synopsis, 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

  • synopsis (String)

    specifies the episode’s synopsis

  • subtitle (String) (defaults to: nil)

    specifies the episode’s subtitle

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

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



20
21
22
23
24
25
26
27
28
29
# File 'lib/woody/episode.rb', line 20

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

Instance Attribute Details

#compilednameObject

Returns the value of attribute compiledname.



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

def compiledname
  @compiledname
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#explicitObject

Returns the value of attribute explicit.



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

def explicit
  @explicit
end

#filenameObject

Returns the value of attribute filename.



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

def filename
  @filename
end

#subtitleObject

Returns the value of attribute subtitle.



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

def subtitle
  @subtitle
end

#synopsisObject

Returns the value of attribute synopsis.



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

def synopsis
  @synopsis
end

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.new_from_meta(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



8
9
10
# File 'lib/woody/episode.rb', line 8

def self.new_from_meta(filename, meta)
  return Episode.new(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



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/woody/episode.rb', line 73

def duration
  return @duration unless @duration.nil?
  length = 0
  Mp3Info.open("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 n’o’.

Returns:

  • (String)

    ‘yes’ if explicit content, otherwise n’o’



68
69
70
# File 'lib/woody/episode.rb', line 68

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

#file_path(leader = true) ⇒ Object

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

Returns:

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



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

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



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

def file_url
  return "#{$config['urlbase']}#{file_path}" unless file_path == false
  return false
end

#keywordsString

Returns a comma separated list of tags, or nil if no tags.

Returns:

  • (String)

    a comma separated list of tags, or nil if no tags



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

def keywords
  @tags.join ', ' unless @tags.nil? or @tags.empty?
end

#path(leader = true) ⇒ Object

Returns the episode’s page path where possible, otherwise false.

Returns:

  • the episode’s page path where possible, otherwise false



40
41
42
43
# File 'lib/woody/episode.rb', line 40

def path(leader=true)
  return "#{leader ? "/" : ""}episode/#{@compiledname[0..-5]}.html" unless @compiledname.nil?
  return false
end

#sizeInteger

Returns the size of the episodes media file in bytes.

Returns:

  • (Integer)

    the size of the episodes media file in bytes



63
64
65
# File 'lib/woody/episode.rb', line 63

def size
  File.size "content/#{filename}"
end

#urlObject

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

Returns:

  • the episode’s page URL where possible, otherwise false



34
35
36
37
# File 'lib/woody/episode.rb', line 34

def url
  return "#{$config['urlbase']}#{path}" unless path == false
  return false
end