Class: LearnOpen::ArgumentParser
- Inherits:
-
Object
- Object
- LearnOpen::ArgumentParser
- Defined in:
- lib/learn_open/argument_parser.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(args) ⇒ ArgumentParser
constructor
A new instance of ArgumentParser.
Constructor Details
#initialize(args) ⇒ ArgumentParser
Returns a new instance of ArgumentParser.
5 6 7 |
# File 'lib/learn_open/argument_parser.rb', line 5 def initialize(args) @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/learn_open/argument_parser.rb', line 3 def args @args end |
Instance Method Details
#execute ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/learn_open/argument_parser.rb', line 9 def execute config_path = File.('~/.learn-config') editor_data = YAML.load(File.read(config_path))[:editor] if editor_data.match(/ /) editor_data = editor_data.split(' ').first end lesson = nil next_lesson = false configured_editor = !(editor_data.empty? || editor_data.nil?) ? editor_data : nil editor_specified = ARGV.detect {|arg| arg.start_with?('--editor=')}.match(/\-\-editor=(.+)/) || configured_editor open_after = !!editor_specified if !ARGV[0].start_with?('--editor=') && !ARGV[0].start_with?('--next') lesson = ARGV[0].sub(/\/$/, '') elsif ARGV[0].start_with?('--next') next_lesson = true end if open_after editor_specified = editor_specified.is_a?(String) ? editor_specified : editor_specified[1] end [lesson, editor_specified, next_lesson] end |