class MyEpisodes::Episode

Constants

ACQUIRED_FIELD
AIR_DATE_FIELD
CHECKED
NAME_FIELD
NUMBER_FIELD
SHOW_NAME_FIELD
WATCHED_FIELD

Attributes

air_date[R]
name[R]
number[R]
show_name[R]

Public Class Methods

new(season) click to toggle source
# File lib/my_episodes/episode.rb, line 7
def initialize(season)
  @season = season
end

Public Instance Methods

acquired?() click to toggle source
# File lib/my_episodes/episode.rb, line 26
def acquired?
  !!@acquired
end
create(attrs) click to toggle source
# File lib/my_episodes/episode.rb, line 11
def create(attrs)
  attrs = sanitize(attrs)
  @air_date = text(attrs[AIR_DATE_FIELD])
  @show_name = text(attrs[SHOW_NAME_FIELD])
  @number = text(attrs[NUMBER_FIELD])
  @name = text(attrs[NAME_FIELD])
  @acquired = checked?(attrs[ACQUIRED_FIELD])
  @watched = checked?(attrs[WATCHED_FIELD])
  self
end
season() click to toggle source
# File lib/my_episodes/episode.rb, line 22
def season
  @season.freeze
end
watched?() click to toggle source
# File lib/my_episodes/episode.rb, line 30
def watched?
  !!@watched
end

Private Instance Methods

checked?(a) click to toggle source
# File lib/my_episodes/episode.rb, line 44
def checked?(a)
  a.children.any? && a.children.last.attr(CHECKED) == CHECKED
end
sanitize(attrs) click to toggle source
# File lib/my_episodes/episode.rb, line 36
def sanitize(attrs)
  attrs.reject.with_index { |a, i| i.even? }
end
text(a) click to toggle source
# File lib/my_episodes/episode.rb, line 40
def text(a)
  a.text.strip
end