Class: Vedeu::Views::HTMLChar

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

Overview

Represents a Char as a HTML tag with value. By default, a table cell is used.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#demodulize, #present?, #snake_case

Constructor Details

#initialize(char, options = {}) ⇒ Vedeu::Views::HTMLChar

Returns a new instance of Vedeu::Views::HTMLChar.

Parameters:

Options Hash (options):

  • start_tag (String)
  • end_tag (String)


28
29
30
31
# File 'lib/vedeu/models/views/html_char.rb', line 28

def initialize(char, options = {})
  @char    = char
  @options = options
end

Instance Attribute Details

#charVedeu::Views::Char (readonly, protected)

Returns:



42
43
44
# File 'lib/vedeu/models/views/html_char.rb', line 42

def char
  @char
end

Class Method Details

.render(char, options = {}) ⇒ String

Parameters:

Options Hash (options):

  • start_tag (String)
  • end_tag (String)

Returns:

  • (String)


17
18
19
# File 'lib/vedeu/models/views/html_char.rb', line 17

def self.render(char, options = {})
  new(char, options).render
end

Instance Method Details

#borderSymbol|NilClass (private)

Returns:

  • (Symbol|NilClass)


129
130
131
# File 'lib/vedeu/models/views/html_char.rb', line 129

def border
  char.border
end

#border_styleString (private)

Returns:

  • (String)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/vedeu/models/views/html_char.rb', line 75

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')}"
  when :top_right    then "#{css('top')}#{css('right')}"
  when :bottom_left  then "#{css('bottom')}#{css('left')}"
  when :bottom_right then "#{css('bottom')}#{css('right')}"
  else
    ''
  end
end

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

Returns:

  • (String)


91
92
93
# File 'lib/vedeu/models/views/html_char.rb', line 91

def css(direction = '')
  "border-#{direction}:1px #{char.foreground.to_html} solid;"
end

#defaultsHash<Symbol => String> (private)

Returns:

  • (Hash<Symbol => String>)


154
155
156
157
158
159
# File 'lib/vedeu/models/views/html_char.rb', line 154

def defaults
  {
    start_tag: '<td',
    end_tag:   '</td>',
  }
end

#end_tagString (private)

Returns:

  • (String)


144
145
146
# File 'lib/vedeu/models/views/html_char.rb', line 144

def end_tag
  options[:end_tag]
end

#optionsHash<Symbol => String> (private)

Returns:

  • (Hash<Symbol => String>)


149
150
151
# File 'lib/vedeu/models/views/html_char.rb', line 149

def options
  defaults.merge!(@options)
end

#renderString

Returns:

  • (String)


34
35
36
# File 'lib/vedeu/models/views/html_char.rb', line 34

def render
  "#{start_tag}#{tag_style}>#{tag_value}#{end_tag}"
end

#start_tagString (private)

Returns:

  • (String)


139
140
141
# File 'lib/vedeu/models/views/html_char.rb', line 139

def start_tag
  options[:start_tag]
end

#tag_styleString (private)

Returns:

  • (String)


47
48
49
50
51
52
53
54
# File 'lib/vedeu/models/views/html_char.rb', line 47

def tag_style
  return '' unless border || present?(value)

  out = " style='"
  out << tag_style_background unless char.background.empty?
  out << tag_style_foreground unless char.foreground.empty?
  out << "'"
end

#tag_style_backgroundString (private)

Returns:

  • (String)


57
58
59
60
# File 'lib/vedeu/models/views/html_char.rb', line 57

def tag_style_background
  "border:1px #{char.background.to_html} solid;" \
    "background:#{char.background.to_html};"
end

#tag_style_foregroundString (private)

Returns:

  • (String)


63
64
65
# File 'lib/vedeu/models/views/html_char.rb', line 63

def tag_style_foreground
  "color:#{char.foreground.to_html};#{border_style}"
end

#tag_valueString (private)

Returns:

  • (String)


68
69
70
71
72
# File 'lib/vedeu/models/views/html_char.rb', line 68

def tag_value
  return '&nbsp;' if border || !present?(value)

  value
end

#valueString (private)

Returns:

  • (String)


134
135
136
# File 'lib/vedeu/models/views/html_char.rb', line 134

def value
  char.value
end