Sha256: 96a7e8fc1e29e7c6221a400a38d3cc28ac8e2f52f74e25ae3b868339edd94b34

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

module Zelda
  class Serie < Zelda::Base
    class << self
      def search(query)
        series = []
        Request.get("series/search/#{query}")['series'].each do |attrs|
          series << Serie.new(attrs)
        end
        series
      end
      
      def find(id)
        attrs = Request.get("series/#{id}")['serie'] rescue nil
        attrs ? new(attrs) : nil
      end
      
      def all
        series = []
        Request.get("series")['series'].each do |attrs|
          series << Serie.new(attrs)
        end
        series
      end
      
      def current
        series = []
        Request.get("current_series")['series'].each do |attrs|
          series << Serie.new(attrs)
        end
        series
      end
    end
  
    def afleveringen(van=nil, tot=nil)
      get_afleveringen(:van => van, :tot => tot)
    end

    def upcoming_afleveringen
      get_afleveringen(:collection => "upcoming")
    end
  
    def past_afleveringen
      get_afleveringen(:collection => "past")
    end
  
    private
      def get_afleveringen(*args)
        @options = args.last.is_a?(::Hash) ? args.pop : {}

        Request.get(url)["afleveringen"].map do |vars|
          Zelda::Aflevering.new(vars)
        end
      end
      
      def url
        if collection = @options[:collection]
          [ "series", serie_id_nebo, "afleveringen", collection ].join("/")
        elsif @options[:van] && @options[:tot]
          van, tot = @options[:van], @options[:tot]
          [ "series", serie_id_nebo, "afleveringen" ].join("/") + "?van=#{van.to_i}&tot=#{tot.to_i}"
        else
          [ "series", serie_id_nebo, "afleveringen" ].join("/")
        end
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zelda-1.2.0 lib/zelda/serie.rb
zelda-1.1.1 lib/zelda/serie.rb
zelda-1.1.0 lib/zelda/serie.rb
zelda-1.0.0 lib/zelda/serie.rb