Module: RNDK::Display

Defined in:
lib/rndk/core/display.rb

Overview

...I still don't know what this module does...

Class Method Summary collapse

Class Method Details

.char_to_display_type(string) ⇒ Object

Given a string, returns the equivalent display type



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rndk/core/display.rb', line 9

def Display.char_to_display_type 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

.filter_by_display_type(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.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rndk/core/display.rb', line 50

def Display.filter_by_display_type(type, input)
  result = input
  if not RNDK.is_char? input
    result = Ncurses::ERR

  elsif ([:INT, :HINT].include? type) and (not RNDK.digit? result.chr)
    result = Ncurses::ERR

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

  elsif type == :VIEWONLY
    result = ERR

  elsif ([:UCHAR, :UHCHAR, :UMIXED, :UHMIXED].include? type) and (RNDK.is_alpha? result.chr)
    result = result.chr.upcase.ord

  elsif ([:LCHAR, :LHCHAR, :LMIXED, :LHMIXED].include? type) and (RNDK.is_alpha? result.chr)
    result = result.chr.downcase.ord
  end
  result
end

.is_hidden_display_type(type) ⇒ Object

Tell if a display type is "hidden"



37
38
39
40
41
42
43
44
45
# File 'lib/rndk/core/display.rb', line 37

def Display.is_hidden_display_type 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