class Kitsu::Anime

Constants

SEASON_PATTERNS

Attributes

data[RW]

Public Class Methods

new(parsed) click to toggle source
# File lib/kitsu/anime.rb, line 12
def initialize(parsed)
  @parsed = parsed
  @data = @parsed['data']
end

Public Instance Methods

ordinalized_words_to_numbers() click to toggle source
# File lib/kitsu/anime.rb, line 17
def ordinalized_words_to_numbers
  @ordinalized_words_to_numbers_map ||= Hash[(1..100).to_a.map do |number|
    word = number.localize.to_rbnf_s('SpelloutRules', 'spellout-ordinal')
    number = number.to_s
    [word, number]
  end]
end
season() click to toggle source
# File lib/kitsu/anime.rb, line 30
def season
  pattern = /#{SEASON_PATTERNS.join('|')}/
  matches = @data['attributes']['titles']['en_jp'].match(pattern)
  return '1' if matches.nil?
  season = matches.captures.compact.first
  return ordinalized_words_to_numbers[season] if season.to_i.zero?
  season
end
title() click to toggle source
# File lib/kitsu/anime.rb, line 25
def title
  en_jp_title = data['attributes']['titles']['en_jp']
  en_jp_title.match(/(^.+?)($|\s\d+\w{2}\sSeason)/).captures[0]
end