Class: Dex::UI::Glyph

Inherits:
Object
  • Object
show all
Defined in:
lib/dex/ui/glyph.rb

Defined Under Namespace

Classes: InvalidGlyphHandle

Constant Summary collapse

MAP =
{}
STAR =

BLACK SMALL STAR

new('*', 0x2b51,  Color::YELLOW)
INFO =

MATHEMATICAL SCRIPT SMALL I

new('i', 0x1d4be, Color::BLUE)
QUESTION =

QUESTION MARK

new('?', 0x003f,  Color::BLUE)
CHECK =

CHECK MARK

new('v', 0x2713,  Color::GREEN)
X =

BALLOT X

new('x', 0x2717,  Color::RED)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handle, codepoint, color) ⇒ Glyph

Returns a new instance of Glyph.



9
10
11
12
13
14
15
16
17
18
# File 'lib/dex/ui/glyph.rb', line 9

def initialize(handle, codepoint, color)
  @handle    = handle
  @codepoint = codepoint
  @color     = color
  @char      = [codepoint].pack('U')
  @to_s      = color.code + char + Color::RESET.code
  @fmt       = "{{#{color.name}:#{char}}}"

  MAP[handle] = self
end

Instance Attribute Details

#charObject (readonly)

Returns the value of attribute char.



8
9
10
# File 'lib/dex/ui/glyph.rb', line 8

def char
  @char
end

#codepointObject (readonly)

Returns the value of attribute codepoint.



8
9
10
# File 'lib/dex/ui/glyph.rb', line 8

def codepoint
  @codepoint
end

#colorObject (readonly)

Returns the value of attribute color.



8
9
10
# File 'lib/dex/ui/glyph.rb', line 8

def color
  @color
end

#fmtObject (readonly)

Returns the value of attribute fmt.



8
9
10
# File 'lib/dex/ui/glyph.rb', line 8

def fmt
  @fmt
end

#handleObject (readonly)

Returns the value of attribute handle.



8
9
10
# File 'lib/dex/ui/glyph.rb', line 8

def handle
  @handle
end

#to_sObject (readonly)

Returns the value of attribute to_s.



8
9
10
# File 'lib/dex/ui/glyph.rb', line 8

def to_s
  @to_s
end

Class Method Details

.availableObject



44
45
46
# File 'lib/dex/ui/glyph.rb', line 44

def self.available
  MAP.keys
end

.lookup(name) ⇒ Object



38
39
40
41
42
# File 'lib/dex/ui/glyph.rb', line 38

def self.lookup(name)
  MAP.fetch(name.to_s)
rescue KeyError
  raise InvalidGlyphHandle, name
end