Sha256: d9cdb2dfa4dfb6ccb18188db09561ce1ad75ff81e412e12dfd530f87e69b1dd5

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

module LearnOpen
  class Opener
    attr_reader :editor,
                :target_lesson,
                :get_next_lesson,
                :io,
                :logger,
                :options

    def self.run(lesson:, editor_specified:, get_next_lesson:)
      new(lesson, editor_specified, get_next_lesson).run
    end

    def initialize(target_lesson, editor, get_next_lesson, options = {})
      @target_lesson = target_lesson
      @editor = editor
      @get_next_lesson = get_next_lesson

      @io = options.fetch(:io, LearnOpen.default_io)
      @logger = options.fetch(:logger, LearnOpen.logger)

      @options = options
    end

    def run
      logger.log('Getting lesson...')
      io.puts "Looking for lesson..."

      lesson_data = LearnOpen::Adapters::LearnWebAdapter
                        .new(options)
                        .fetch_lesson_data(
                            target_lesson: target_lesson,
                            fetch_next_lesson: get_next_lesson
                        )

      lesson = Lessons.classify(lesson_data, options)
      environment = LearnOpen::Environments.classify(options)
      lesson.open(environment, editor)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
learn-open-1.2.22 lib/learn_open/opener.rb
learn-open-1.2.21 lib/learn_open/opener.rb