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/row.rb
Defined Under Namespace
Classes: Row
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
Methods included from PP::Dashboard::Table
Constructor Details
#initialize(options = {}) ⇒ Table
Returns a new instance of Table.
19 20 21 22 23 24 25 26 27 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 19 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.
10 11 12 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 10 def bodies @bodies end |
#body ⇒ Object
Returns the value of attribute body.
10 11 12 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 10 def body @body end |
#header ⇒ Object
Returns the value of attribute header.
10 11 12 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 10 def header @header end |
#headers ⇒ Object
Returns the value of attribute headers.
10 11 12 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 10 def headers @headers end |
#opt ⇒ Object
Returns the value of attribute opt.
10 11 12 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 10 def opt @opt end |
#rows ⇒ Object
Returns the value of attribute rows.
10 11 12 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 10 def rows @rows end |
#side ⇒ Object
Returns the value of attribute side.
10 11 12 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 10 def side @side end |
#sides ⇒ Object
Returns the value of attribute sides.
10 11 12 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 10 def sides @sides end |
Instance Method Details
#add_body {|b = Wrapper.new| ... } ⇒ Object
41 42 43 44 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 41 def add_body yield b = Wrapper.new body << b end |
#add_header {|header| ... } ⇒ Object
33 34 35 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 33 def add_header yield header end |
#add_side {|side| ... } ⇒ Object
37 38 39 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 37 def add_side yield side end |
#each ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 88 def each if block_given? rows.each do |r| yield r end else rows.each end end |
#map ⇒ Object Also known as: collect
98 99 100 101 102 103 104 105 106 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 98 def map if block_given? rows.map do |r| yield r end else rows.map end end |
#matrix? ⇒ Boolean
29 30 31 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 29 def matrix? opt[:matrix] end |
#parse! ⇒ Object
46 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 |
# File 'lib/deep/hash/struct/dashboard/table.rb', line 46 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? merge_body = body.shift body.size.times do bs.merge! body.shift end sides.map do |s| rs = [] rs << s rs += headers.map do |h| next if h.side_header? v = merge_body.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 |