Module: CDK::Display

Defined in:
lib/cdk/display.rb

Class Method Summary collapse

Class Method Details

.filterByDisplayType(type, input) ⇒ Object

Given a character input, check if it is allowed by the display type and return the character to apply to the display, or ERR if not



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cdk/display.rb', line 30

def Display.filterByDisplayType(type, input)
  result = input
  if !CDK.isChar(input)
    result = Ncurses::ERR

  elsif [:INT, :HINT].include?(type) &&
        !CDK.digit?(result.chr)
    result = Ncurses::ERR

  elsif [:CHAR, :UCHAR, :LCHAR, :UHCHAR, :LHCHAR].include?(type) &&
        CDK.digit?(result.chr)
    result = Ncurses::ERR

  elsif type == :VIEWONLY
    result = ERR

  elsif [:UCHAR, :UHCHAR, :UMIXED, :UHMIXED].include?(type) &&
        CDK.alpha?(result.chr)
    result = result.chr.upcase.ord

  elsif [:LCHAR, :LHCHAR, :LMIXED, :LHMIXED].include?(type) &&
        CDK.alpha?(result.chr)
    result = result.chr.downcase.ord
  end

  return result
end

.isHiddenDisplayType(type) ⇒ Object

Tell if a display type is “hidden”



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cdk/display.rb', line 4

def Display.isHiddenDisplayType(type)
  case type
  when :HCHAR,
       :HINT,
       :HMIXED,
       :LHCHAR,
       :LHMIXED,
       :UHCHAR,
       :UHMIXED
    true

  when :CHAR,
       :INT,
       :INVALID,
       :LCHAR,
       :LMIXED,
       :MIXED,
       :UCHAR,
       :UMIXED,
       :VIEWONLY
    false
  end
end