File: helpers.rb

package info (click to toggle)
ruby-test-unit-context 0.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 188 kB
  • sloc: ruby: 810; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 615 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'time'

module Test::Unit::Context
  module Helpers
    
    CONST_NAME_SUB_ = /[\s:\-'",\.~;!?#=\(\)&]+/ # :nodoc:
    
    module_function
    
    def to_const_name(str, prefix = nil, suffix = nil)
      name = str.dup
      name.lstrip! if prefix
      name.rstrip! if suffix
      name.gsub!(CONST_NAME_SUB_, '_')
      name.gsub!(/\/(.?)/) { $1.upcase }
      name.gsub!(/(?:^|_)(.)/) { $1.upcase }
      "#{prefix}#{name}#{suffix}"
    end
    
    def generate_uuid
      uuid = [ (Time.now.to_f * 1000).to_i % 10 ]
      15.times { uuid << rand(16).to_s(16) }
      uuid.join
    end
    
  end
end