Class: Sycsvpro::ScriptList

Inherits:
Object
  • Object
show all
Defined in:
lib/sycsvpro/script_list.rb

Overview

Lists the contents of the script directory. Optionally listing a specific script file and also optionally the methods and associated description of the methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ScriptList

Creates a new ScriptList. Takes params script_dir, script_file and show_methods



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sycsvpro/script_list.rb', line 18

def initialize(options={})
  @script_dir   = options[:dir]
  @script_type  = options[:type] || 'script'
  @script_type.downcase!
  @script_file  = options[:script] || '*.rb'  if @script_type == 'script'
  @script_file  = options[:script] || '*.ins' if @script_type == 'insert'
  @script_file  = options[:script] || '*.{rb,ins}' if @script_type == 'all'
  @show_methods = options[:show_methods] if @script_type == 'script'
  @show_methods = false if @script_type == 'insert'
  @list         = {}
end

Instance Attribute Details

#listObject (readonly)

Hash holding the list of scripts



15
16
17
# File 'lib/sycsvpro/script_list.rb', line 15

def list
  @list
end

#script_dirObject (readonly)

Directory that holds the scripts



9
10
11
# File 'lib/sycsvpro/script_list.rb', line 9

def script_dir
  @script_dir
end

#script_fileObject (readonly)

Script file of interest



11
12
13
# File 'lib/sycsvpro/script_list.rb', line 11

def script_file
  @script_file
end

#show_methodsObject (readonly)

Switch indicating whether to show methods



13
14
15
# File 'lib/sycsvpro/script_list.rb', line 13

def show_methods
  @show_methods
end

Instance Method Details

#executeObject

Retrieves the information about scripts and methods from the script directory



31
32
33
34
35
36
37
38
39
40
# File 'lib/sycsvpro/script_list.rb', line 31

def execute
  scripts = Dir.glob(File.join(@script_dir, @script_file))
  scripts.each do |script|
    list[script] = []
    if show_methods
      list[script] = retrieve_methods(script)
    end
  end
  list
end