Class: Woody::Episode
- Inherits:
-
Object
- Object
- Woody::Episode
- Defined in:
- lib/woody/episode.rb
Overview
Represents an episode of the podcast
Instance Attribute Summary collapse
-
#compiledname ⇒ Object
Returns the value of attribute compiledname.
-
#date ⇒ Object
Returns the value of attribute date.
-
#explicit ⇒ Object
Returns the value of attribute explicit.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#subtitle ⇒ Object
Returns the value of attribute subtitle.
-
#synopsis ⇒ Object
Returns the value of attribute synopsis.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
-
.new_from_meta(filename, meta) ⇒ Episode
Creates a new Episode object from segment of metadata.yml.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#duration ⇒ String
The duration of the media file, formatted as minutes:seconds.
-
#explicit_string ⇒ String
‘yes’ if explicit content, otherwise n’o’.
-
#file_path(leader = true) ⇒ Object
The episode’s media file path where possible, otherwise false.
-
#file_url ⇒ Object
The episode’s media file URL where possible, otherwise false.
-
#initialize(filename, title, date, synopsis, subtitle = nil, tags = [], explicit = false) ⇒ Episode
constructor
Creates a new Episode object.
-
#keywords ⇒ String
A comma separated list of tags, or nil if no tags.
-
#path(leader = true) ⇒ Object
The episode’s page path where possible, otherwise false.
-
#size ⇒ Integer
The size of the episodes media file in bytes.
-
#url ⇒ Object
The episode’s page URL where possible, otherwise false.
Constructor Details
#initialize(filename, title, date, synopsis, subtitle = nil, tags = [], explicit = false) ⇒ Episode
Creates a new Episode object
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, = [], explicit = false) @filename = filename @title = title @date = date @synopsis = synopsis @subtitle = subtitle @tags = @explicit = explicit @compiledname = @filename.gsub(/[^0-9A-Za-z .]/, '').gsub(' ', '_') end |
Instance Attribute Details
#compiledname ⇒ Object
Returns the value of attribute compiledname.
31 32 33 |
# File 'lib/woody/episode.rb', line 31 def compiledname @compiledname end |
#date ⇒ Object
Returns the value of attribute date.
31 32 33 |
# File 'lib/woody/episode.rb', line 31 def date @date end |
#explicit ⇒ Object
Returns the value of attribute explicit.
31 32 33 |
# File 'lib/woody/episode.rb', line 31 def explicit @explicit end |
#filename ⇒ Object
Returns the value of attribute filename.
31 32 33 |
# File 'lib/woody/episode.rb', line 31 def filename @filename end |
#subtitle ⇒ Object
Returns the value of attribute subtitle.
31 32 33 |
# File 'lib/woody/episode.rb', line 31 def subtitle @subtitle end |
#synopsis ⇒ Object
Returns the value of attribute synopsis.
31 32 33 |
# File 'lib/woody/episode.rb', line 31 def synopsis @synopsis end |
#tags ⇒ Object
Returns the value of attribute tags.
31 32 33 |
# File 'lib/woody/episode.rb', line 31 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
31 32 33 |
# File 'lib/woody/episode.rb', line 31 def title @title end |
Class Method Details
Instance Method Details
#<=>(other) ⇒ Object
85 86 87 |
# File 'lib/woody/episode.rb', line 85 def <=> (other) other.date <=> self.date end |
#duration ⇒ String
Returns 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(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_string ⇒ String
Returns ‘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.
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_url ⇒ Object
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 |
#keywords ⇒ String
Returns 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.
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 |
#size ⇒ Integer
Returns the size of the episodes media file in bytes.
63 64 65 |
# File 'lib/woody/episode.rb', line 63 def size File.size File.join("content", filename) end |
#url ⇒ Object
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 |