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?, #to_sentence

Constructor Details

#initialize(char) ⇒ Vedeu::HTMLChar

Parameters:



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

def initialize(char)
  @char = char
end

Instance Attribute Details

#charObject (readonly, private)

Returns the value of attribute char.



30
31
32
# File 'lib/vedeu/output/html_char.rb', line 30

def char
  @char
end

Class Method Details

.render(char) ⇒ String

Parameters:

Returns:

  • (String)


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

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

Instance Method Details

#bgString (private)

Returns:

  • (String)


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

def bg
  @bg ||= colour_bg || parent_bg || '#000'
end

#borderSymbol|NilClass (private)

Returns:

  • (Symbol|NilClass)


110
111
112
# File 'lib/vedeu/output/html_char.rb', line 110

def border
  char.border
end

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

Returns:

  • (String)


67
68
69
# File 'lib/vedeu/output/html_char.rb', line 67

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

#border_styleString (private)

Returns:

  • (String)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vedeu/output/html_char.rb', line 47

def border_style
  case border
  when nil                then ''
  when :top_horizontal    then border_css('top')
  when :left_vertical     then border_css('left')
  when :right_vertical    then border_css('right')
  when :bottom_horizontal then border_css('bottom')
  when :top_left          then [border_css('top'), border_css('left')].join
  when :top_right         then [border_css('top'), border_css('right')].join
  when :bottom_left       then [border_css('bottom'), border_css('left')].join
  when :bottom_right      then [border_css('bottom'), border_css('right')].join
  when :horizontal        then ''
  when :vertical          then ''
  else
    # ... should not get here
    ''
  end
end

#colour_bgString|NilClass (private)

Returns:

  • (String|NilClass)


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

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

#colour_fgString|NilClass (private)

Returns:

  • (String|NilClass)


89
90
91
92
93
# File 'lib/vedeu/output/html_char.rb', line 89

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

#fgString (private)

Returns:

  • (String)


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

def fg
  @fg ||= colour_fg || parent_fg || '#222'
end

#parent_bgString|NilClass (private)

Returns:

  • (String|NilClass)


96
97
98
99
100
# File 'lib/vedeu/output/html_char.rb', line 96

def parent_bg
  if char.parent_background && defined_value?(char.parent_background.to_html)
    char.parent_background.to_html
  end
end

#parent_fgString|NilClass (private)

Returns:

  • (String|NilClass)


103
104
105
106
107
# File 'lib/vedeu/output/html_char.rb', line 103

def parent_fg
  if char.parent_foreground && defined_value?(char.parent_foreground.to_html)
    char.parent_foreground.to_html
  end
end

#renderString

Returns:

  • (String)


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

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

#td_styleString (private)

Returns:

  • (String)


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

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)


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

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

  value
end

#valueString (private)

Returns:

  • (String)


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

def value
  char.value
end