Class: LearnOpen::Opener

Inherits:
Object
  • Object
show all
Defined in:
lib/learn_open/opener.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_lesson, editor, get_next_lesson, clone_only, options = {}) ⇒ Opener

Returns a new instance of Opener.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/learn_open/opener.rb', line 15

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

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

  @options = options
end

Instance Attribute Details

#clone_onlyObject (readonly)

Returns the value of attribute clone_only.



3
4
5
# File 'lib/learn_open/opener.rb', line 3

def clone_only
  @clone_only
end

#editorObject (readonly)

Returns the value of attribute editor.



3
4
5
# File 'lib/learn_open/opener.rb', line 3

def editor
  @editor
end

#get_next_lessonObject (readonly)

Returns the value of attribute get_next_lesson.



3
4
5
# File 'lib/learn_open/opener.rb', line 3

def get_next_lesson
  @get_next_lesson
end

#ioObject (readonly)

Returns the value of attribute io.



3
4
5
# File 'lib/learn_open/opener.rb', line 3

def io
  @io
end

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/learn_open/opener.rb', line 3

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/learn_open/opener.rb', line 3

def options
  @options
end

#target_lessonObject (readonly)

Returns the value of attribute target_lesson.



3
4
5
# File 'lib/learn_open/opener.rb', line 3

def target_lesson
  @target_lesson
end

Class Method Details

.run(lesson:, editor_specified:, get_next_lesson:, clone_only:) ⇒ Object



11
12
13
# File 'lib/learn_open/opener.rb', line 11

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

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/learn_open/opener.rb', line 27

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, clone_only)
end