Sha256: 4c7c86f977030372dd6f59a70a0630adff6dcdc3518431313bc80e7c46b470d1

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

# Copyright (C) 2016 Mikio Ikoma

# Common part of regextest
module Regextest::Common
  # Analyzing options
  @@parse_options = nil
  @@rand_called = false
  
  # environment variables
  TstConstRetryMax     = (ENV['REGEXTEST_MAX_RETRY'])?(ENV['REGEXTEST_MAX_RETRY'].to_i):5
  TstConstRepeatMax    = (ENV['REGEXTEST_MAX_REPEAT'])?(ENV['REGEXTEST_MAX_REPEAT'].to_i):32
  TstConstRecursionMax = (ENV['REGEXTEST_MAX_RECURSION'])?(ENV['REGEXTEST_MAX_RECURSION'].to_i):32
  TstConstDebug        = (ENV['REGEXTEST_DEBUG'])?true:false
  TstConstTimeout      = (ENV['REGEXTEST_TIMEOUT'])?(ENV['REGEXTEST_TIMEOUT'].to_f):1.0 # default is 1 second
  
  # whole character set if unicode mode. specify as 'ascii|kana', 'ascii|han|kana', etc.
  TstConstUnicodeCharSet  = (ENV['REGEXTEST_UNICODE_CHAR_SET'] || "ascii|katakana|hiragana").downcase

  # Log
  def TstLog(msg)
    # if(!defined? Rails)  # not output debug message when rails env (even if development mode)
    if TstConstDebug
      warn msg
    end
    # end
  end
  
  # Randomize
  def TstRand(num)
    @@rand_called = true
    rand(num)
  end
  
  # Shuffle
  def TstShuffle(array)
    @@rand_called = true
    array.shuffle
  end
  
  # reset random_called
  def reset_random_called
    @@rand_called = false
  end
  
  # is_random?
  def is_random?
    @@rand_called
  end
  
  # Pretty print of matched data object
  def TstMdPrint(md)
    # coloring if tty && (!windows)
    if $stdout.tty? && !RUBY_PLATFORM.downcase.match(/mswin(?!ce)|mingw/)
      "#{md.pre_match.inspect[1..-2]}\e[36m#{md.to_a[0].inspect[1..-2]}\e[0m#{md.post_match.inspect[1..-2]}"
    else
      "#{md.pre_match.inspect[1..-2]} #{md.to_a[0].inspect[1..-2]} #{md.post_match.inspect[1..-2]}"
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
regextest-0.1.5 lib/regextest/common.rb
regextest-0.1.4 lib/regextest/common.rb
regextest-0.1.3 lib/regextest/common.rb
regextest-0.1.2 lib/regextest/common.rb