Sha256: 383b58881d7baf7f540a66c8f2af543af4dfcaa299d6c23fcce59f410a127027

Contents?: true

Size: 872 Bytes

Versions: 1

Compression:

Stored size: 872 Bytes

Contents

module LearnOpen
  class ArgumentParser
    attr_reader :args

    def initialize(args)
      @args = args
    end

    def execute
      config_path = File.expand_path('~/.learn-config')
      editor_data = YAML.load(File.read(config_path))[:editor]
      if editor_data.match(/ /)
        editor_data = editor_data.split(' ').first
      end

      lesson = nil

      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=')
        lesson = ARGV[0]
      end

      if open_after
        editor_specified = editor_specified.is_a?(String) ? editor_specified : editor_specified[1]
      end

      [lesson, editor_specified]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
learn-open-1.0.5 lib/learn_open/argument_parser.rb