Class: PinoyFilter::Anime

Inherits:
Object
  • Object
show all
Defined in:
lib/PinoyFilter/Classes/Anime.rb

Overview

The anime class holds @name, @url and @id. It also let you retrieve a list of episodes that are available.

Constant Summary collapse

@@count =

To keep count of animes and allow one to refer to them easier, we keep a list of them

0

Instance Method Summary collapse

Constructor Details

#initialize(elem) ⇒ void

Returns Regardless of what happends.

Initializes the Anime class

Parameters:

  • elem (Nokogiri::Element)

    A 'a' tag element from Nokogiri

Raises:

  • (ArgumentError)

15
16
17
18
19
20
21
# File 'lib/PinoyFilter/Classes/Anime.rb', line 15

def initialize(element)
  raise ArgumentError.new("This is not a valid Nokogiri::XML::Element") unless element.class == Nokogiri::XML::Element
  @name = element.text
  @url = element['href']
  @@count += 1
  @id = @@count
end

Instance Method Details

#episodesPinoyFilter::Episode[]

Returns an array of episodes.

Returns:


68
69
70
71
72
73
74
# File 'lib/PinoyFilter/Classes/Anime.rb', line 68

def episodes
  if !@episodes
    @episodes = PinoyFilter::SiteHandler.GetEpisodes(@url, nil, self)
  end

  return @episodes
end

#idint

Returns the self assigned ID. Based on @@count

Returns:

  • (int)

    Self assigned ID


54
55
56
# File 'lib/PinoyFilter/Classes/Anime.rb', line 54

def id
  return @id
end

#inspectString

Used to inspect the elements in IRB. The output has not been prettified for use in production.

Hides URL and episodes which would've been present on standard inspect.

Returns:

  • (String)

    Output string


63
64
65
# File 'lib/PinoyFilter/Classes/Anime.rb', line 63

def inspect
  return "#{self}, #{@id}, #{@name}"
end

#nameString

The name of the anime

Returns:

  • (String)

    name


42
43
44
# File 'lib/PinoyFilter/Classes/Anime.rb', line 42

def name
  return @name
end

#urlString

Returns anime URL as string

Returns:

  • (String)

    url


48
49
50
# File 'lib/PinoyFilter/Classes/Anime.rb', line 48

def url
  return @url
end

#valid?true, false

Will check if this anime is valid. Can be used to filter bad animes out. And by bad, I mean invalid. Not Sword Art Online, trollololllollol. This function is being called by the SiteHandler and will require this to return true, for it to be added to the list. This is a bad way of doing it.

Triggers

  • If the link does not go to “pinoyanime.tv”. I know this currently breaks the entire concept of being able to use other links. But until I pass the Site class into this its going to be broken for any custom sites.

Returns:

  • (true)

    If the link is valid.

  • (false)

    If it triggers any of the criterias


36
37
38
# File 'lib/PinoyFilter/Classes/Anime.rb', line 36

def valid?
  @url.include? "pinoyanime.tv" or @url.include? "theanime.tv"
end