class PopcorntimeSearch::Search

Attributes

episode[RW]
kind[RW]
season[RW]
title[RW]

Public Class Methods

new(search) click to toggle source
# File lib/popcorntime_search/search.rb, line 10
def initialize(search)
  @title   = search[TITLE_REGEXP, :showname].strip

  season   = search[SEASON_EPISODE_REGEXP, :season]
  episode  = search[SEASON_EPISODE_REGEXP, :episode]
  @season  = season.to_i if season
  @episode = episode.to_i if episode

  @kind = @season ? :show : :movie
end

Public Instance Methods

full_season?() click to toggle source
# File lib/popcorntime_search/search.rb, line 38
def full_season?
  @season && !@episode
end
results() click to toggle source
# File lib/popcorntime_search/search.rb, line 21
def results
  @results ||= self.class.get("/#{@kind}s/1", query: { keywords: @title }).map do |result|
    case @kind
    when :movie
      MovieResult.new(result)
    when :show
      ShowResult.new(result, @season, @episode)
    end
  end
end
results_found?() click to toggle source
# File lib/popcorntime_search/search.rb, line 32
def results_found?
  @results_found ||= results.count > 0
rescue SocketError
  @results_found = false
end