Class: Gauge::Util

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

Class Method Summary collapse

Class Method Details

.get_file_name(prefix = '', counter = 0) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/util.rb', line 41

def self.get_file_name(prefix = '', counter = 0)
  name = "step_implementation#{prefix}.rb"
  file_name = File.join(get_step_implementation_dir, name)
  return file_name unless File.file? file_name
  counter += 1
  get_file_name("_#{counter}", counter)
end

.get_step_implementation_dirObject



37
38
39
# File 'lib/util.rb', line 37

def self.get_step_implementation_dir
  return File.join(ENV["GAUGE_PROJECT_ROOT"].gsub(/\\/, "/"), 'step_implementations')
end

.remove_special_chars(param) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/util.rb', line 27

def self.remove_special_chars(param)
  new_param = ''
  param.each_char {|c|
    if valid_variable_name? c
      new_param += c
    end
  }
  return new_param
end

.valid_variable_name?(var_name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/util.rb', line 20

def self.valid_variable_name?(var_name)
  Object.new.instance_variable_set ('@' + var_name).to_sym, nil
  true
rescue NameError
  !!(var_name =~ /^[0-9]+$/)
end