Class: MarkdownExec::MarkParse

Inherits:
Object
  • Object
show all
Includes:
ArrayUtil, StringUtil
Defined in:
lib/markdown_exec.rb

Overview

:reek:DuplicateMethodCall { allow_calls: [‘block’, ‘item’, ‘lm’, ‘opts’, ‘option’, ‘@options’, ‘required_blocks’] } rubocop:enable Layout/LineLength :reek:MissingSafeMethod { exclude: [ read_configuration_file! ] } :reek:TooManyInstanceVariables ### temp :reek:TooManyMethods ### temp

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StringUtil

partition_at_first

Methods included from ArrayUtil

partition_by_predicate

Constructor Details

#initialize(options = {}) ⇒ MarkParse

Returns a new instance of MarkParse.



119
120
121
122
123
124
# File 'lib/markdown_exec.rb', line 119

def initialize(options = {})
  @option_parser = nil

  @options = HashDelegator.new(options)
  @fout = FOut.new(@delegate_object)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



114
115
116
# File 'lib/markdown_exec.rb', line 114

def options
  @options
end

#promptObject (readonly)

Returns the value of attribute prompt.



114
115
116
# File 'lib/markdown_exec.rb', line 114

def prompt
  @prompt
end

#run_stateObject (readonly)

Returns the value of attribute run_state.



114
115
116
# File 'lib/markdown_exec.rb', line 114

def run_state
  @run_state
end

Instance Method Details

#determine_filename(specified_filename: nil, specified_folder: nil, default_filename: nil, default_folder: nil, filetree: nil) ⇒ Object

Determines the correct filename to use for searching files



186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/markdown_exec.rb', line 186

def determine_filename(specified_filename: nil, specified_folder: nil, default_filename: nil,
                       default_folder: nil, filetree: nil)
  if specified_filename&.present?
    return specified_filename if specified_filename.start_with?('/')

    File.join(specified_folder || default_folder, specified_filename)
  elsif specified_folder&.present?
    File.join(specified_folder,
              filetree ? @options[:md_filename_match] : @options[:md_filename_glob])
  else
    File.join(default_folder, default_filename)
  end
end

#list_files_specified(fn, filetree = nil) ⇒ Object

Searches for files based on the specified or default filenames and folders



443
444
445
446
447
448
449
# File 'lib/markdown_exec.rb', line 443

def list_files_specified(fn, filetree = nil)
  return Dir.glob(fn) unless filetree

  filetree.select do |filename|
    filename == fn || filename.match(/^#{fn}$/) || filename.match(%r{^#{fn}/.+$})
  end
end

#list_markdown_files_in_pathObject



451
452
453
454
# File 'lib/markdown_exec.rb', line 451

def list_markdown_files_in_path
  Dir.glob(File.join(@options[:path],
                     @options[:md_filename_glob]))
end

#runObject



533
534
535
536
537
538
539
540
# File 'lib/markdown_exec.rb', line 533

def run
  initialize_and_parse_cli_options
  execute_block_with_error_handling
rescue StandardError
  error_handler('run')
ensure
  yield if block_given?
end

#tab_completions(data = menu_for_optparse) ⇒ Object



623
624
625
626
627
# File 'lib/markdown_exec.rb', line 623

def tab_completions(data = menu_for_optparse)
  data.map do |item|
    "--#{item[:long_name]}" if item[:long_name]
  end.compact
end

#update_options(opts = {}, over: true) ⇒ Object

:reek:BooleanParameter :reek:ControlParameter



631
632
633
634
635
636
637
638
# File 'lib/markdown_exec.rb', line 631

def update_options(opts = {}, over: true)
  if over
    @options = @options.merge opts
  else
    @options.merge! opts
  end
  @options
end