Module: Bumbleworks::Support
- Defined in:
- lib/bumbleworks/support.rb,
lib/bumbleworks/support/flow_expression.rb,
lib/bumbleworks/support/wrapper_comparison.rb
Overview
Support methods for utility functionality such as string modification - could also be accomplished by monkey-patching String class.
Defined Under Namespace
Modules: FlowExpression, WrapperComparison
Classes: WaitTimeout
Class Method Summary
collapse
Class Method Details
.all_files(directory, options = {}) ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/bumbleworks/support.rb', line 13
def all_files(directory, options = {})
Dir["#{directory}/**/*.rb"].inject({}) do |memo, path|
name = File.basename(path, '.rb')
name = camelize(name) if options[:camelize] == true
memo[path] = name
memo
end
end
|
.camelize(string) ⇒ Object
8
9
10
11
|
# File 'lib/bumbleworks/support.rb', line 8
def camelize(string)
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
string = string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
end
|
.constantize(name) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/bumbleworks/support.rb', line 22
def constantize(name)
name_parts = name.split('::')
name_parts.shift if name_parts.first.empty?
constant = Object
name_parts.each do |name_part|
const_defined_args = [name_part]
const_defined_args << false unless Module.method(:const_defined?).arity == 1
constant_defined = constant.const_defined?(*const_defined_args)
constant = constant_defined ? constant.const_get(name_part) : constant.const_missing(name_part)
end
constant
end
|
.humanize(string) ⇒ Object
44
45
46
47
48
|
# File 'lib/bumbleworks/support.rb', line 44
def humanize(string)
return nil if string.nil?
tokenize(string).gsub(/_/, ' ').
gsub(/^\w/) { $&.upcase }
end
|
.titleize(string) ⇒ Object
50
51
52
53
|
# File 'lib/bumbleworks/support.rb', line 50
def titleize(string)
return nil if string.nil?
humanize(string).gsub(/\b('?[a-z])/) { $1.capitalize }
end
|
.tokenize(string) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/bumbleworks/support.rb', line 36
def tokenize(string)
return nil if string.nil?
string = string.to_s.gsub(/&/, ' and ').
gsub(/[ \/]+/, '_').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
downcase
end
|
.wait_until(options = {}, &block) ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/bumbleworks/support.rb', line 55
def wait_until(options = {}, &block)
options[:timeout] ||= Bumbleworks.timeout
start_time = Time.now
until block.call
if (Time.now - start_time) > options[:timeout]
raise WaitTimeout
end
sleep 0.1
end
end
|