Module: Card::Format::Nesting::Subformat
- Included in:
- Card::Format::Nesting
- Defined in:
- lib/card/format/nesting/subformat.rb
Overview
Formats can have subformats. Lineage can be retraced through “parent” format.
Instance Method Summary collapse
- #depth ⇒ Object
- #field_subformat(field) ⇒ Object
-
#focal? ⇒ Boolean
is format’s card the format of the requested card? (can be different from main in certain formats, see override in HtmlFormat).
- #inherit(variable) ⇒ Object
- #main ⇒ Object
-
#main? ⇒ Boolean
is format’s card the format of the main card on a page?.
- #root ⇒ Object
- #root? ⇒ Boolean
-
#subformat(subcard, opts = {}) ⇒ Object
NOTE: while it is possible to have a subformat of a different class, the :format_class value takes precedence over :format.
Instance Method Details
#depth ⇒ Object
26 27 28 |
# File 'lib/card/format/nesting/subformat.rb', line 26 def depth @depth ||= parent ? (parent.depth + 1) : 0 end |
#field_subformat(field) ⇒ Object
45 46 47 48 |
# File 'lib/card/format/nesting/subformat.rb', line 45 def field_subformat field field = card.name.field(field) unless field.is_a?(Card) subformat field end |
#focal? ⇒ Boolean
is format’s card the format of the requested card? (can be different from main in certain formats, see override in HtmlFormat)
41 42 43 |
# File 'lib/card/format/nesting/subformat.rb', line 41 def focal? @focal ||= depth.zero? end |
#inherit(variable) ⇒ Object
50 51 52 53 |
# File 'lib/card/format/nesting/subformat.rb', line 50 def inherit variable variable = "@#{variable}" unless variable.to_s.start_with? "@" instance_variable_get(variable) || parent&.inherit(variable) end |
#main ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/card/format/nesting/subformat.rb', line 18 def main if main? self elsif !root? parent.main end end |
#main? ⇒ Boolean
is format’s card the format of the main card on a page?
35 36 37 |
# File 'lib/card/format/nesting/subformat.rb', line 35 def main? depth.zero? end |
#root ⇒ Object
14 15 16 |
# File 'lib/card/format/nesting/subformat.rb', line 14 def root @root ||= parent ? parent.root : self end |
#root? ⇒ Boolean
30 31 32 |
# File 'lib/card/format/nesting/subformat.rb', line 30 def root? depth.zero? end |
#subformat(subcard, opts = {}) ⇒ Object
NOTE: while it is possible to have a subformat of a different class, the :format_class value takes precedence over :format.
8 9 10 11 12 |
# File 'lib/card/format/nesting/subformat.rb', line 8 def subformat subcard, opts={} subcard = subformat_card subcard opts = opts.merge(parent: self).reverse_merge(format_class: self.class) self.class.new subcard, opts end |