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.



158
159
160
161
162
163
# File 'lib/markdown_exec.rb', line 158

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.



153
154
155
# File 'lib/markdown_exec.rb', line 153

def options
  @options
end

#promptObject (readonly)

Returns the value of attribute prompt.



153
154
155
# File 'lib/markdown_exec.rb', line 153

def prompt
  @prompt
end

#run_stateObject (readonly)

Returns the value of attribute run_state.



153
154
155
# File 'lib/markdown_exec.rb', line 153

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



225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/markdown_exec.rb', line 225

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



499
500
501
502
503
504
505
# File 'lib/markdown_exec.rb', line 499

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



507
508
509
510
# File 'lib/markdown_exec.rb', line 507

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

#runObject



589
590
591
592
593
594
595
596
# File 'lib/markdown_exec.rb', line 589

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



678
679
680
681
682
# File 'lib/markdown_exec.rb', line 678

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



686
687
688
689
690
691
692
693
# File 'lib/markdown_exec.rb', line 686

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