Class: Vedeu::HTMLChar

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/vedeu/output/html_char.rb

Overview

Represents a Char as a HTML table cell.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#defined_value?

Constructor Details

#initialize(char) ⇒ Vedeu::HTMLChar

Returns a new instance of Vedeu::HTMLChar.

Parameters:



20
21
22
# File 'lib/vedeu/output/html_char.rb', line 20

def initialize(char)
  @char = char
end

Instance Attribute Details

#charVedeu::Char (readonly, protected)

Returns:



33
34
35
# File 'lib/vedeu/output/html_char.rb', line 33

def char
  @char
end

Class Method Details

.render(char) ⇒ String

Parameters:

Returns:

  • (String)


12
13
14
# File 'lib/vedeu/output/html_char.rb', line 12

def self.render(char)
  new(char).render
end

Instance Method Details

#bgString (private)

Returns:

  • (String)


82
83
84
# File 'lib/vedeu/output/html_char.rb', line 82

def bg
  @bg ||= colour_bg
end

#borderSymbol|NilClass (private)

Returns:

  • (Symbol|NilClass)


115
116
117
# File 'lib/vedeu/output/html_char.rb', line 115

def border
  char.border
end

#border_styleString (private)

Returns:

  • (String)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/vedeu/output/html_char.rb', line 56

def border_style
  case border
  when :top_horizontal    then css('top')
  when :left_vertical     then css('left')
  when :right_vertical    then css('right')
  when :bottom_horizontal then css('bottom')
  when :top_left     then [css('top'), css('left')].join
  when :top_right    then [css('top'), css('right')].join
  when :bottom_left  then [css('bottom'), css('left')].join
  when :bottom_right then [css('bottom'), css('right')].join
  else
    ''
  end
end

#colour_bgString (private)

Returns:

  • (String)


87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/vedeu/output/html_char.rb', line 87

def colour_bg
  if defined_value?(char.background.to_html)
    char.background.to_html

  elsif defined_value?(char.parent_background.to_html)
    char.parent_background.to_html

  else
    '#000'

  end
end

#colour_fgString (private)

Returns:

  • (String)


101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/vedeu/output/html_char.rb', line 101

def colour_fg
  if defined_value?(char.foreground.to_html)
    char.foreground.to_html

  elsif defined_value?(char.parent_foreground.to_html)
    char.parent_foreground.to_html

  else
    '#222'

  end
end

#css(direction = '') ⇒ String (private)

Returns:

  • (String)


72
73
74
# File 'lib/vedeu/output/html_char.rb', line 72

def css(direction = '')
  "border-#{direction}:1px #{fg} solid;"
end

#fgString (private)

Returns:

  • (String)


77
78
79
# File 'lib/vedeu/output/html_char.rb', line 77

def fg
  @fg ||= colour_fg
end

#renderString

Returns:

  • (String)


25
26
27
# File 'lib/vedeu/output/html_char.rb', line 25

def render
  "<td#{td_style}>#{td_value}</td>"
end

#td_styleString (private)

Returns:

  • (String)


38
39
40
41
42
43
44
45
46
# File 'lib/vedeu/output/html_char.rb', line 38

def td_style
  return '' unless border || defined_value?(value)

  " style='" \
  "background:#{bg};" \
  "color:#{fg};" \
  "border:1px #{bg} solid;" \
  "#{border_style}'"
end

#td_valueString (private)

Returns:

  • (String)


49
50
51
52
53
# File 'lib/vedeu/output/html_char.rb', line 49

def td_value
  return '&nbsp;' if border || !defined_value?(value)

  value
end

#valueString (private)

Returns:

  • (String)


120
121
122
# File 'lib/vedeu/output/html_char.rb', line 120

def value
  char.value
end