Module: CDK::Display

Defined in:
lib/cdk/display.rb

Class Method Summary collapse

Class Method Details

.char2DisplayType(string) ⇒ Object

Given a string, returns the equivalent display type



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

def Display.char2DisplayType(string)
  table = {
    "CHAR"     => :CHAR,
    "HCHAR"    => :HCHAR,
    "INT"      => :INT,
    "HINT"     => :HINT,
    "UCHAR"    => :UCHAR,
    "LCHAR"    => :LCHAR,
    "UHCHAR"   => :UHCHAR,
    "LHCHAR"   => :LHCHAR,
    "MIXED"    => :MIXED,
    "HMIXED"   => :HMIXED,
    "UMIXED"   => :UMIXED,
    "LMIXED"   => :LMIXED,
    "UHMIXED"  => :UHMIXED,
    "LHMIXED"  => :LHMIXED,
    "VIEWONLY" => :VIEWONLY,
    0          => :INVALID 
  }
 
  if table.include?(string)
    table[string]
  else
    :INVALID
  end
end

.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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cdk/display.rb', line 44

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”



32
33
34
35
36
37
38
39
40
# File 'lib/cdk/display.rb', line 32

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