Class: Docp::TableHeader
- Inherits:
-
Object
- Object
- Docp::TableHeader
- Includes:
- TableHeaderPtn
- Defined in:
- lib/docp/table_header.rb
Defined Under Namespace
Classes: Column
Instance Attribute Summary collapse
-
#after_to_hash ⇒ Object
Returns the value of attribute after_to_hash.
-
#before_parse ⇒ Object
TableOption.
-
#child ⇒ Object
readonly
Returns the value of attribute child.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#default_format ⇒ Object
RowOption.
-
#match_block(&block) ⇒ Object
readonly
Returns the value of attribute match_block.
-
#required_attributes ⇒ Object
(also: #required_keys)
Returns the value of attribute required_attributes.
-
#vertical ⇒ Object
Returns the value of attribute vertical.
Attributes included from TableHeaderPtn
#after_check_val, #exclude_ptn, #include_ptn
Instance Method Summary collapse
- #[](name) ⇒ Object
- #add(h) {|col| ... } ⇒ Object
-
#include_ptn?(tr) ⇒ Boolean
if match_block CreateSelfInstance & Schema == Child.
-
#initialize(match = nil, args = {}, &block) ⇒ TableHeader
constructor
A new instance of TableHeader.
- #no_hash_keys ⇒ Object
- #required_all?(tr) ⇒ Boolean
- #required_columns ⇒ Object
- #set_required_columns ⇒ Object
- #swap(h) ⇒ Object
Methods included from TableHeaderPtn
#check_ptn, #exclude_ptn?, #ptn?
Constructor Details
#initialize(match = nil, args = {}, &block) ⇒ TableHeader
Returns a new instance of TableHeader.
21 22 23 24 25 26 27 28 29 |
# File 'lib/docp/table_header.rb', line 21 def initialize match = nil, args = {}, &block @columns = [] @required_columns = [] @required_attributes = [] args.each {|k, v| send("#{k}=", v) } @default_format ||= :text block.call(self, match) set_required_columns end |
Instance Attribute Details
#after_to_hash ⇒ Object
Returns the value of attribute after_to_hash.
17 18 19 |
# File 'lib/docp/table_header.rb', line 17 def after_to_hash @after_to_hash end |
#before_parse ⇒ Object
TableOption
12 13 14 |
# File 'lib/docp/table_header.rb', line 12 def before_parse @before_parse end |
#child ⇒ Object (readonly)
Returns the value of attribute child.
8 9 10 |
# File 'lib/docp/table_header.rb', line 8 def child @child end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
6 7 8 |
# File 'lib/docp/table_header.rb', line 6 def columns @columns end |
#default_format ⇒ Object
RowOption
16 17 18 |
# File 'lib/docp/table_header.rb', line 16 def default_format @default_format end |
#match_block(&block) ⇒ Object (readonly)
Returns the value of attribute match_block.
7 8 9 |
# File 'lib/docp/table_header.rb', line 7 def match_block @match_block end |
#required_attributes ⇒ Object Also known as: required_keys
Returns the value of attribute required_attributes.
9 10 11 |
# File 'lib/docp/table_header.rb', line 9 def required_attributes @required_attributes end |
#vertical ⇒ Object
Returns the value of attribute vertical.
13 14 15 |
# File 'lib/docp/table_header.rb', line 13 def vertical @vertical end |
Instance Method Details
#[](name) ⇒ Object
51 52 53 54 |
# File 'lib/docp/table_header.rb', line 51 def [] name name = name.to_sym if name.is_a?(String) @columns.find {|col| col.name == name} end |
#add(h) {|col| ... } ⇒ Object
95 96 97 98 99 100 |
# File 'lib/docp/table_header.rb', line 95 def add h col = Column.new(h.merge(default_format: @default_format)) yield col if block_given? @columns.push(*[col, col.children].flatten) col end |
#include_ptn?(tr) ⇒ Boolean
if match_block CreateSelfInstance & Schema == Child
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/docp/table_header.rb', line 37 def include_ptn? tr [@include_ptn || @columns.map(&:include_ptn)].flatten.map.with_index do|ptn, i| if ptn?(tr.search('*'), ptn) match = {ptn: ptn, index: i, tr: tr} @child = TableHeader.new match, &@match_block if @match_block if @child return !@child.exclude_ptn?(tr.search('*')) else return true end end end.any? end |
#no_hash_keys ⇒ Object
91 92 93 |
# File 'lib/docp/table_header.rb', line 91 def no_hash_keys @columns.select(&:no_hash).map(&:name) end |
#required_all?(tr) ⇒ Boolean
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/docp/table_header.rb', line 78 def required_all? tr return true if required_columns.empty? cols = required_columns.select {|col| col.include_ptn?(tr.row_elements) } if cols.count >= required_keys.count true else keys = required_keys.dup cols.each {|col| keys.delete(col.name)} #header_required_undefineds = { keys: keys, tr: tr.clone } nil end end |
#required_columns ⇒ Object
74 75 76 |
# File 'lib/docp/table_header.rb', line 74 def required_columns @columns.select {|col| col.required} end |
#set_required_columns ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/docp/table_header.rb', line 56 def set_required_columns #keys = @required_attributes.select {|name| [email protected] {|col| col.name == name} } #raise "Column NotFound #{keys}" if keys.any? if @required_attributes.any? @columns.select do|col| f = @required_attributes.find {|name| col.name == name} f ? col.required = true : col.required = false end else required_columns.map {|col| col.required = false } end end |