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

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)


25
26
27
28
# File 'lib/vedeu/models/views/html_char.rb', line 25

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

Instance Attribute Details

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

Returns:



39
40
41
# File 'lib/vedeu/models/views/html_char.rb', line 39

def char
  @char
end

Class Method Details

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

Parameters:

Returns:

  • (String)


14
15
16
# File 'lib/vedeu/models/views/html_char.rb', line 14

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

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#borderSymbol|NilClass (private)

Returns:

  • (Symbol|NilClass)


94
95
96
# File 'lib/vedeu/models/views/html_char.rb', line 94

def border
  char.border
end

#border_styleString (private)

Returns:

  • (String)


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

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

#css(direction) ⇒ String (private)

Parameters:

  • direction (Symbol)

Returns:

  • (String)


89
90
91
# File 'lib/vedeu/models/views/html_char.rb', line 89

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

#defaultsHash<Symbol => String> (private)

Returns:

  • (Hash<Symbol => String>)


119
120
121
122
123
124
# File 'lib/vedeu/models/views/html_char.rb', line 119

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

#demodulize(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#end_tagString (private)

Returns:

  • (String)


109
110
111
# File 'lib/vedeu/models/views/html_char.rb', line 109

def end_tag
  options[:end_tag]
end

#optionsHash<Symbol => String> (private)

Returns:

  • (Hash<Symbol => String>)


114
115
116
# File 'lib/vedeu/models/views/html_char.rb', line 114

def options
  defaults.merge!(@options)
end

#present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#renderString

Returns:

  • (String)


31
32
33
# File 'lib/vedeu/models/views/html_char.rb', line 31

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

#snake_case(name) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

#start_tagString (private)

Returns:

  • (String)


104
105
106
# File 'lib/vedeu/models/views/html_char.rb', line 104

def start_tag
  options[:start_tag]
end

#tag_styleString (private)

Returns:

  • (String)


44
45
46
47
48
49
50
51
# File 'lib/vedeu/models/views/html_char.rb', line 44

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 << "'".freeze
end

#tag_style_backgroundString (private)

Returns:

  • (String)


54
55
56
57
# File 'lib/vedeu/models/views/html_char.rb', line 54

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

#tag_style_foregroundString (private)

Returns:

  • (String)


60
61
62
# File 'lib/vedeu/models/views/html_char.rb', line 60

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

#tag_valueString (private)

Returns:

  • (String)


65
66
67
68
69
# File 'lib/vedeu/models/views/html_char.rb', line 65

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

  value
end

#valueString (private)

Returns:

  • (String)


99
100
101
# File 'lib/vedeu/models/views/html_char.rb', line 99

def value
  char.value
end