class Daigaku::Views::ChaptersMenu

Private Instance Methods

before_enter(*args) click to toggle source
# File lib/daigaku/views/chapters_menu.rb, line 8
def before_enter(*args)
  @course = args[0]
end
before_reenter(*args) click to toggle source
# File lib/daigaku/views/chapters_menu.rb, line 12
def before_reenter(*args)
  @course   = args[0]
  @chapter  = args[1]
  @position = @course.chapters.find_index(@chapter)
end
header_text() click to toggle source
# File lib/daigaku/views/chapters_menu.rb, line 18
def header_text
  "*#{@course.title}* - available chapters:"
end
interact_with(window) click to toggle source
# File lib/daigaku/views/chapters_menu.rb, line 22
def interact_with(window)
  while char = window.getch
    case char
    when KEY_UP
      @position -= 1
      broadcast(:reset_menu_position)
    when KEY_DOWN
      @position += 1
      broadcast(:reset_menu_position)
    when 10 # Enter
      broadcast(:enter, @course, models[@position])
      return
    when 263 # Backspace
      broadcast(:reenter, @course)
      return
    when 27 # ESC
      exit
    end

    @position = items.length - 1 if @position < 0
    @position = 0 if @position >= items.length
    draw(window, @position)
  end
end
items() click to toggle source
# File lib/daigaku/views/chapters_menu.rb, line 51
def items
  models.map(&:title)
end
models() click to toggle source
# File lib/daigaku/views/chapters_menu.rb, line 47
def models
  @course.chapters
end