Class: Deep::Hash::Struct::Dashboard::Table::Tr

Inherits:
Object
  • Object
show all
Includes:
PP::Dashboard::Table::Tr
Defined in:
lib/deep/hash/struct/dashboard/table/tr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PP::Dashboard::Table::Tr

#inspect, #pretty_print

Constructor Details

#initialize(header, body, side, options = {}) ⇒ Tr

Returns a new instance of Tr.



11
12
13
14
15
16
# File 'lib/deep/hash/struct/dashboard/table/tr.rb', line 11

def initialize(header, body, side, options = {})
  @header  = header
  @body    = body
  @side    = side
  @options = options
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



9
10
11
# File 'lib/deep/hash/struct/dashboard/table/tr.rb', line 9

def body
  @body
end

#headerObject

Returns the value of attribute header.



9
10
11
# File 'lib/deep/hash/struct/dashboard/table/tr.rb', line 9

def header
  @header
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/deep/hash/struct/dashboard/table/tr.rb', line 9

def options
  @options
end

#sideObject

Returns the value of attribute side.



9
10
11
# File 'lib/deep/hash/struct/dashboard/table/tr.rb', line 9

def side
  @side
end

Instance Method Details

#td(value = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/deep/hash/struct/dashboard/table/tr.rb', line 48

def td(value = nil)
  hash = {}
  if !value.is_a?(Array) && value.respond_to?(:each)
    if value.has_key?(:key) && value.has_key?(:value)
      hash[value[:key]] = value[:value]
    else
      value.each do |k, v|
        hash[k] = v
      end
    end
  else
    i = body.count + 1
    hash["key_#{i}"] = value
  end

  if options[:side]
    hash.each do |k, v|
      body[k][side.keys[options[:b_index]]] = v
    end
  else
    body.merge! hash
  end
end

#th(value = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/deep/hash/struct/dashboard/table/tr.rb', line 18

def th(value = nil)
  hash = {}
  if !value.is_a?(Array) && value.respond_to?(:each)
    if value.has_key?(:key) && value.has_key?(:value)
      hash[value[:key]] = value[:value]
    else
      value.each do |k, v|
        hash[k] = v
      end
    end
  else
    i = if options[:side]
          side.count + 1
        elsif options[:matrix]
          header.count
        else
          header.count + 1
        end
    hash["key_#{i}"] = value
  end

  if options[:side]
    side.merge! hash
  else
    header.merge! hash
  end

  value
end