Sha256: 5a750cd33b5c83094bf2921064f040531660506550d915517a75c19a1fa657b1

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require 'belajar/views/menu'

module Belajar
  module Views

    class CoursesMenu < Menu

      private

      def header_text
        'Available belajar courses:'
      end

      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, models[@position])
              return
            when 27 # ESC
              exit
          end

          @position = items.length - 1 if @position < 0
          @position = 0 if @position >= items.length
          draw(window, @position)
        end
      end

      def models
        Loading::Courses.load(Belajar.config.courses_path)
      end

      def items
        non_empty_courses = models.select { |course| !course.chapters.empty? }

        non_empty_courses.map do |course|
          line = "#{course.title}"
          self.items_info <<= [(course.author ? "(by #{course.author})" : '')]
          line
        end
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
belajar-0.1.1 lib/belajar/views/courses_menu.rb