class MyanimelistClient::SearchEntry

This class is used to reprensent an entry within a {SearchResponse}. It can describe either an anime or a manga.

@example

require 'myanimelist_client'

client = MyanimelistClient.new 'username', 'password'

client.search_anime('anime name').each do |entry|
  # entry is a SearchResponse.

  # It exposes all its attributes:
  entry.id                # => String or nil
  entry.title             # => String or nil
  entry.english           # => String or nil
  entry.synonyms          # => String or nil
  entry.episodes          # => Fixnum or nil
  entry.chapters          # => Fixnum or nil
  entry.volumes           # => Fixnum or nil
  entry.score             # => Float or nil
  entry.type              # => String or nil
  entry.status            # => String or nil
  entry.start_date        # => String or nil
  entry.end_date          # => String or nil
  entry.synopsis          # => String or nil
  entry.image             # => String or nil

  # It provides some useful predicates:
  entry.manga?            # => true or false
  entry.anime?            # => true or false
  entry.upcoming?         # => true or false
  entry.ongoing?          # => true or false
  entry.finished?         # => true or false

  # It can be converted to a hash:
  entry.to_h              # => Hash
end

@attr [String, nil] id Returns the ID. @attr [String, nil] title Returns the title. @attr [String, nil] english Returns the english title. @attr [String, nil] synonyms Returns the synonyms. @attr [Fixnum, nil] episodes Returns the number of episodes (nil when the entry describes a manga). @attr [Fixnum, nil] chapters Returns the number of chapters (nil when the entry describes an anime). @attr [Fixnum, nil] volumes Returns the number of volumes (nil when the entry describes an anime). @attr [Float, nil] score Returns the score. @attr [String, nil] type Returns the type. @attr [String, nil] status Returns the status. @attr [String, nil] start_date Returns the start date. @attr [String, nil] end_date Returns the end date. @attr [String, nil] synopsis Returns the synopsis. @attr [String, nil] image Returns the image's URL.

Constants

ATTRIBUTES

The list of attributes defining the entry for internal usage.

Public Class Methods

new(options={}) click to toggle source

@param [Hash] options A hash used to hydrate the object.

# File lib/myanimelist_client/search_entry.rb, line 77
def initialize options={}
  ATTRIBUTES.each do |attribute|
    instance_variable_set "@#{attribute}", options[attribute] || options[attribute.to_sym]
  end
end

Public Instance Methods

==(other) click to toggle source

Performs a loose equality based on the value of the attributes (see {ATTRIBUTES}).

# File lib/myanimelist_client/search_entry.rb, line 91
def == other
  ATTRIBUTES.each do |attribute|
    if !other.respond_to?(attribute) || send(attribute) != other.send(attribute)
      return false
    end
  end
  true
end
anime?() click to toggle source

Returns true when the entry describes an anime.

# File lib/myanimelist_client/search_entry.rb, line 101
def anime?
  @episodes.to_i > 0
end
finished?() click to toggle source

Returns true when the anime or manga is finished.

# File lib/myanimelist_client/search_entry.rb, line 121
def finished?
  !!(/finished/i =~ @status)
end
manga?() click to toggle source

Returns true when the entry describes a manga.

# File lib/myanimelist_client/search_entry.rb, line 106
def manga?
  @chapters.to_i > 0 || @volumes.to_i > 0
end
ongoing?() click to toggle source

Returns true when the anime is currently airing / when the manga is currently publishing.

# File lib/myanimelist_client/search_entry.rb, line 116
def ongoing?
  !!(/currently|publishing/i =~ @status)
end
to_h() click to toggle source

Creates a hash representing the entry. @return [Hash]

# File lib/myanimelist_client/search_entry.rb, line 85
def to_h
  values = ATTRIBUTES.map{ |attribute| send attribute }
  Hash[ATTRIBUTES.zip values]
end
upcoming?() click to toggle source

Returns true when the anime is not yet aired / when the manga is not yet published.

# File lib/myanimelist_client/search_entry.rb, line 111
def upcoming?
  !!(/not\s+yet/i =~ @status)
end