Class: Regextest::Front::Range::TRange

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/regextest/front/range.rb

Constant Summary collapse

@@id =

a class variable for generating unique name of element

0

Constants included from Common

Common::TstConstDebug, Common::TstConstRecursionMax, Common::TstConstRepeatMax, Common::TstConstRetryMax, Common::TstConstRetryMaxSecond, Common::TstConstTimeout, Common::TstConstUnicodeCharSet, Common::TstFixnumMax

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#TstLog, #TstMdPrint, #TstRand, #TstShuffle, #is_random?, #reset_random_called

Constructor Details

#initialize(letter_begin, letter_end = nil) ⇒ TRange

Constructor



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/regextest/front/range.rb', line 15

def initialize(letter_begin, letter_end = nil)
  TstLog("TRange: #{letter_begin}-#{letter_end}")
  @options = nil
  @begin = parse_letter(letter_begin)
  if letter_end 
    @end = parse_letter(letter_end)
  else
    @end = @begin
  end

  @offset = -1  # not used in this class
  @length = -1  # not used in this class
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



29
30
31
# File 'lib/regextest/front/range.rb', line 29

def length
  @length
end

#offsetObject (readonly)

Returns the value of attribute offset.



29
30
31
# File 'lib/regextest/front/range.rb', line 29

def offset
  @offset
end

Instance Method Details

#enumerateObject

enumerate



46
47
48
# File 'lib/regextest/front/range.rb', line 46

def enumerate
  (@begin..@end).to_a
end

#jsonObject

transform to json format (using codepoints of Unicode)



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/regextest/front/range.rb', line 57

def json
  @@id += 1
  if @options
    charset = @options[:reg_options].charset
  else
    charset = "d"
  end
  "{" +
    "\"type\": \"LEX_RANGE\", " +
    "\"id\": \"G#{@@id}\", " +
    "\"begin\": #{@begin}, " +
    "\"end\": #{@end}, " +
    "\"charset\": \"#{charset}\"" +
  "}"
end

#parse_letter(letter) ⇒ Object

parse letter



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/regextest/front/range.rb', line 32

def parse_letter(letter)
  case letter
  when String
    letter.unpack("U*")[0]
  when Integer
    letter
  when Regextest::Front::Letter::TLetter
    eval('"' + letter.value + '"').unpack("U*")[0]
  else
    raise "Internal error. invalid letter class #{letter}"
  end
end

#set_options(options) ⇒ Object

set options



51
52
53
54
# File 'lib/regextest/front/range.rb', line 51

def set_options(options)
  TstLog("Range set_options: #{options[:reg_options].inspect}")
  @options = options
end