Class: Woody::Episode
Overview
Represents an episode of the podcast. Inherits from Post.
Instance Attribute Summary collapse
-
#explicit ⇒ Object
Returns the value of attribute explicit.
Attributes inherited from Post
#compiledname, #date, #filename, #raw_body, #subtitle, #tags, #title
Class Method Summary collapse
-
.new_from_meta(site, filename, meta) ⇒ Episode
Creates a new Episode object from segment of metadata.yml.
Instance Method Summary collapse
-
#duration ⇒ String
The duration of the media file, formatted as minutes:seconds.
-
#explicit_string ⇒ String
‘yes’ if explicit content, otherwise ‘no’.
-
#file_path(leader = true) ⇒ Object
The episode’s media file path! where possible, otherwise false.
-
#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.
- #has_file? ⇒ Boolean
-
#initialize(site, filename, title, date, raw_body, subtitle = nil, tags = [], explicit = false) ⇒ Episode
constructor
Creates a new Episode object.
-
#size ⇒ Integer
The size of the episodes media file in bytes.
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
22 23 24 25 26 |
# File 'lib/woody/episode.rb', line 22 def initialize(site, filename, title, date, raw_body, subtitle = nil, = [], explicit = false) super site, filename, title, subtitle, raw_body, date, @explicit = explicit @compiledname = @filename.gsub(/[^0-9A-Za-z ._]/, '').gsub(' ', '_') end |
Instance Attribute Details
#explicit ⇒ Object
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
10 11 12 |
# File 'lib/woody/episode.rb', line 10 def self.(site, filename, ) return Episode.new(site, filename, ['title'], Date.parse(['date'].to_s), ['synopsis'], ['subtitle'], ['tags'], ['explicit']) end |
Instance Method Details
#duration ⇒ String
Returns 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_string ⇒ String
Returns ‘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.
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.
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_url ⇒ Object
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
76 77 78 |
# File 'lib/woody/episode.rb', line 76 def has_file? true end |
#size ⇒ Integer
Returns 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 |