Class: Jekyll::Podcast::EpisodeData
- Inherits:
-
Object
- Object
- Jekyll::Podcast::EpisodeData
- Defined in:
- lib/jekyll/podcast/episode_data.rb
Overview
Class responsible for setting episode data on a post’s page
Instance Method Summary collapse
- #add_episode_data ⇒ Object
- #duration(seconds) ⇒ Object
- #guid ⇒ Object
-
#initialize(page, payload) ⇒ EpisodeData
constructor
A new instance of EpisodeData.
- #seconds ⇒ Object
- #size ⇒ Object
- #size_in_megabytes ⇒ Object
Constructor Details
#initialize(page, payload) ⇒ EpisodeData
Returns a new instance of EpisodeData.
8 9 10 11 12 |
# File 'lib/jekyll/podcast/episode_data.rb', line 8 def initialize(page, payload) @site = page.site @page = payload['page'] @file_path = File.join(Jekyll::Podcast::Utils.episodes_dir(@site), @page['podcast']['file']) end |
Instance Method Details
#add_episode_data ⇒ Object
14 15 16 17 18 19 |
# File 'lib/jekyll/podcast/episode_data.rb', line 14 def add_episode_data @page['podcast'].merge!({ 'size' => size, 'size_in_megabytes' => size_in_megabytes, 'duration' => duration(seconds), 'guid' => guid }) end |
#duration(seconds) ⇒ Object
41 42 43 44 |
# File 'lib/jekyll/podcast/episode_data.rb', line 41 def duration(seconds) format('%<hours>d:%<minutes>02d:%<seconds>02d', Jekyll::Podcast::Utils.duration(seconds)) end |
#guid ⇒ Object
46 47 48 |
# File 'lib/jekyll/podcast/episode_data.rb', line 46 def guid @page['podcast']['guid'] || "#{@site.config['url']}#{@page['url']}" end |
#seconds ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/jekyll/podcast/episode_data.rb', line 33 def seconds if File.exist? @file_path Mp3Info.open(@file_path, &:length) else 0 end end |
#size ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/jekyll/podcast/episode_data.rb', line 21 def size if File.exist? @file_path File.size(@file_path) else 0 end end |
#size_in_megabytes ⇒ Object
29 30 31 |
# File 'lib/jekyll/podcast/episode_data.rb', line 29 def size_in_megabytes "#{(size / 1_000_000.0).round(1)} MB" end |