Class: Episode
- Inherits:
-
Struct
- Object
- Struct
- Episode
- Includes:
- Comparable
- Defined in:
- lib/gst-kitchen/episode.rb
Instance Attribute Summary collapse
-
#auphonic_uuid ⇒ Object
Returns the value of attribute auphonic_uuid.
-
#chapters ⇒ Object
Returns the value of attribute chapters.
-
#length ⇒ Object
Returns the value of attribute length.
-
#media ⇒ Object
Returns the value of attribute media.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number ⇒ Object
Returns the value of attribute number.
-
#podcast ⇒ Object
Returns the value of attribute podcast.
-
#published_at ⇒ Object
Returns the value of attribute published_at.
-
#subtitle ⇒ Object
Returns the value of attribute subtitle.
-
#summary ⇒ Object
Returns the value of attribute summary.
Class Method Summary collapse
- .extract_episode_data_from_auphonic(podcast, production) ⇒ Object
- .extract_episode_number(handle, title) ⇒ Object
- .extract_name(handle, title) ⇒ Object
- .from_auphonic(podcast, production) ⇒ Object
- .from_yaml(podcast, yaml_file) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #duration ⇒ Object
- #handle ⇒ Object
-
#initialize(podcast = nil, *args) ⇒ Episode
constructor
A new instance of Episode.
- #rfc_2822_date ⇒ Object
- #title ⇒ Object
- #to_s ⇒ Object
- #to_yaml_properties ⇒ Object
Constructor Details
#initialize(podcast = nil, *args) ⇒ Episode
Returns a new instance of Episode.
68 69 70 71 |
# File 'lib/gst-kitchen/episode.rb', line 68 def initialize(podcast=nil, *args) @podcast = podcast super(*args) end |
Instance Attribute Details
#auphonic_uuid ⇒ Object
Returns the value of attribute auphonic_uuid
1 2 3 |
# File 'lib/gst-kitchen/episode.rb', line 1 def auphonic_uuid @auphonic_uuid end |
#chapters ⇒ Object
Returns the value of attribute chapters
1 2 3 |
# File 'lib/gst-kitchen/episode.rb', line 1 def chapters @chapters end |
#length ⇒ Object
Returns the value of attribute length
1 2 3 |
# File 'lib/gst-kitchen/episode.rb', line 1 def length @length end |
#media ⇒ Object
Returns the value of attribute media
1 2 3 |
# File 'lib/gst-kitchen/episode.rb', line 1 def media @media end |
#name ⇒ Object
Returns the value of attribute name
1 2 3 |
# File 'lib/gst-kitchen/episode.rb', line 1 def name @name end |
#number ⇒ Object
Returns the value of attribute number
1 2 3 |
# File 'lib/gst-kitchen/episode.rb', line 1 def number @number end |
#podcast ⇒ Object
Returns the value of attribute podcast.
4 5 6 |
# File 'lib/gst-kitchen/episode.rb', line 4 def podcast @podcast end |
#published_at ⇒ Object
Returns the value of attribute published_at
1 2 3 |
# File 'lib/gst-kitchen/episode.rb', line 1 def published_at @published_at end |
#subtitle ⇒ Object
Returns the value of attribute subtitle
1 2 3 |
# File 'lib/gst-kitchen/episode.rb', line 1 def subtitle @subtitle end |
#summary ⇒ Object
Returns the value of attribute summary
1 2 3 |
# File 'lib/gst-kitchen/episode.rb', line 1 def summary @summary end |
Class Method Details
.extract_episode_data_from_auphonic(podcast, production) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gst-kitchen/episode.rb', line 38 def extract_episode_data_from_auphonic(podcast, production) data = production. = { auphonic_uuid: data["data"]["uuid"], number: extract_episode_number(podcast.handle, data["data"]["metadata"]["title"]), length: data["data"]["length"], name: extract_name(podcast.handle, data["data"]["metadata"]["title"]), subtitle: data["data"]["metadata"]["subtitle"].strip, summary: data["data"]["metadata"]["summary"].strip, } [:media] = data["data"]["output_files"].each_with_object({}) do |item, obj| obj[item["format"]] = { "size" => item["size"], "file_ext" => item["ending"] } end [:chapters] = if data["data"]["chapters"] [:chapters] = data["data"]["chapters"].map do |chapter| Chapter.new(chapter["start"], chapter["title"]) end.sort end end |
.extract_episode_number(handle, title) ⇒ Object
30 31 32 |
# File 'lib/gst-kitchen/episode.rb', line 30 def extract_episode_number(handle, title) title.match(/#{handle}(\d{3})/) { |match| match[1].to_i } end |
.extract_name(handle, title) ⇒ Object
34 35 36 |
# File 'lib/gst-kitchen/episode.rb', line 34 def extract_name(handle, title) title.match(/#{handle}\d{3} ?- ?(.*)$/) { |match| match[1] } end |
.from_auphonic(podcast, production) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gst-kitchen/episode.rb', line 7 def from_auphonic(podcast, production) = extract_episode_data_from_auphonic(podcast, production) episode = self.new podcast episode.number = [:number] episode.name = [:name] episode.subtitle = [:subtitle] episode.length = [:length].round episode.auphonic_uuid = [:auphonic_uuid] episode.published_at = Time.now episode.summary = [:summary] episode.media = [:media] episode.chapters = [:chapters] episode end |
.from_yaml(podcast, yaml_file) ⇒ Object
24 25 26 27 28 |
# File 'lib/gst-kitchen/episode.rb', line 24 def from_yaml(podcast, yaml_file) episode = YAML.load_file(yaml_file) episode.podcast = podcast episode end |
Instance Method Details
#<=>(other) ⇒ Object
73 74 75 |
# File 'lib/gst-kitchen/episode.rb', line 73 def <=>(other) self.number <=> other.number end |
#duration ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/gst-kitchen/episode.rb', line 89 def duration hours = length / (60 * 60) minutes = (length - hours * 60 * 60) / 60 seconds = length % 60 "#{"%02i" % hours}:#{"%02i" % minutes}:#{"%02i" % seconds}" end |
#handle ⇒ Object
81 82 83 |
# File 'lib/gst-kitchen/episode.rb', line 81 def handle "#{podcast.handle}#{"%03i" % self.number}" end |
#rfc_2822_date ⇒ Object
85 86 87 |
# File 'lib/gst-kitchen/episode.rb', line 85 def rfc_2822_date self.published_at.rfc2822 end |
#title ⇒ Object
77 78 79 |
# File 'lib/gst-kitchen/episode.rb', line 77 def title "#{handle} - #{name}" end |
#to_s ⇒ Object
97 98 99 |
# File 'lib/gst-kitchen/episode.rb', line 97 def to_s "#{title} (#{duration}) https://auphonic.com/engine/status/#{auphonic_uuid}" end |
#to_yaml_properties ⇒ Object
101 102 103 |
# File 'lib/gst-kitchen/episode.rb', line 101 def to_yaml_properties super - [:@podcast] end |