Sha256: b78a798b5b9a09db2b163a6f0251576f95e4752dbfa3d535f390e6c8dffcfe19

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

module Feedjira
  module Podcast
    module Item
      module Optional
        def self.included(base)

          base.element :link do |link|
            Addressable::URI.parse(link)
          end

          base.element :author

          base.elements :category

          base.element :comments do |comments|
            Addressable::URI.parse(comments)
          end

          def categories
            category.map{|c|c.strip}.uniq
          end

          base.element :enclosure, as: :enclosure_url, value: :url do |url|
            Addressable::URI.parse(url)
          end

          base.element :enclosure, as: :enclosure_length, value: :length
          base.element :enclosure, as: :enclosure_type, value: :type

          def enclosure
            @enclosure ||= Struct.new(:url, :length, :type).new(
              enclosure_url,
              (enclosure_length && enclosure_length.to_f),
              enclosure_type,
            )
          end

          base.element :guid, as: :guid, class: GUID, default: Struct.new(:guid, :perma_link?).new

          base.element :pubDate, as: :pub_date do |date|
            begin
              Time.parse(date)
            rescue
              nil
            end
          end

          base.element :source do |source|
            Addressable::URI.parse(source)
          end

        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
feedjira-podcast-0.9.1 lib/feedjira/podcast/item/optional.rb
feedjira-podcast-0.9.0 lib/feedjira/podcast/item/optional.rb