Class: Deep::Hash::Struct::Dashboard::Table
- Inherits:
-
Object
- Object
- Deep::Hash::Struct::Dashboard::Table
- Includes:
- PP::Dashboard::Table
- Defined in:
- lib/deep/hash/struct/dashboard/table.rb,
lib/deep/hash/struct/dashboard/table/tr.rb,
lib/deep/hash/struct/dashboard/table/row.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#bodies ⇒ Object
Returns the value of attribute bodies.
-
#body ⇒ Object
Returns the value of attribute body.
-
#header ⇒ Object
Returns the value of attribute header.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#opt ⇒ Object
Returns the value of attribute opt.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#side ⇒ Object
Returns the value of attribute side.
-
#sides ⇒ Object
Returns the value of attribute sides.
Instance Method Summary collapse
- #add_body {|b = Wrapper.new| ... } ⇒ Object
- #add_header {|header| ... } ⇒ Object
- #add_side {|side| ... } ⇒ Object
- #each ⇒ Object
-
#initialize(options = {}) ⇒ Table
constructor
A new instance of Table.
- #map ⇒ Object (also: #collect)
- #matrix? ⇒ Boolean
- #parse! ⇒ Object
- #tr(options = {}) {|Tr.new(header, b, side, opt)| ... } ⇒ Object
Methods included from PP::Dashboard::Table
Constructor Details
#initialize(options = {}) ⇒ Table
20 21 22 23 24 25 26 27 28 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 20 def initialize( = {}) self.opt = .merge() self.header = Wrapper.new self.side = Wrapper.new self.body = [] self.bodies = [] self.rows = [] header.side_header = opt[:side_header] if matrix? end |
Instance Attribute Details
#bodies ⇒ Object
Returns the value of attribute bodies.
11 12 13 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 11 def bodies @bodies end |
#body ⇒ Object
Returns the value of attribute body.
11 12 13 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 11 def body @body end |
#header ⇒ Object
Returns the value of attribute header.
11 12 13 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 11 def header @header end |
#headers ⇒ Object
Returns the value of attribute headers.
11 12 13 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 11 def headers @headers end |
#opt ⇒ Object
Returns the value of attribute opt.
11 12 13 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 11 def opt @opt end |
#rows ⇒ Object
Returns the value of attribute rows.
11 12 13 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 11 def rows @rows end |
#side ⇒ Object
Returns the value of attribute side.
11 12 13 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 11 def side @side end |
#sides ⇒ Object
Returns the value of attribute sides.
11 12 13 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 11 def sides @sides end |
Instance Method Details
#add_body {|b = Wrapper.new| ... } ⇒ Object
42 43 44 45 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 42 def add_body yield b = Wrapper.new body << b end |
#add_header {|header| ... } ⇒ Object
34 35 36 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 34 def add_header yield header end |
#add_side {|side| ... } ⇒ Object
38 39 40 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 38 def add_side yield side end |
#each ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 90 def each if block_given? rows.each do |r| yield r end else rows.each end end |
#map ⇒ Object Also known as: collect
100 101 102 103 104 105 106 107 108 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 100 def map if block_given? rows.map do |r| yield r end else rows.map end end |
#matrix? ⇒ Boolean
30 31 32 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 30 def matrix? opt[:matrix] end |
#parse! ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 47 def parse! raise_check! self.headers = header.map.each_with_index do |(k, v), i| Row.new(header: true, side: matrix? && i.zero?, name: v, value: k) end self.sides = side.map do |k, v| Row.new(side: true, name: v, value: k) end self.bodies = if matrix? bs = Wrapper.new body.size.times do bs.deep_merge! body.shift end sides.map do |s| rs = [] rs << s rs += headers.map do |h| next if h.side_header? v = bs.to_h.dig(h.value, s.value) v = v.nil? ? opt[:default] : v Row.new(value: v) end.compact rs end else body.map do |r| headers.map do |h| v = r.to_h.dig(h.value) v = v.nil? ? opt[:default] : v Row.new(value: v) end.compact end end self.rows << headers self.rows += bodies end |
#tr(options = {}) {|Tr.new(header, b, side, opt)| ... } ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 111 def tr( = {}) b = Wrapper.new opt[:side] = [:side] || false opt[:matrix] = matrix? opt[:b_index] = body.size yield Tr.new(header, b, side, opt) body << b unless b.count.zero? self end |