Module: Card::Format::Nest::Subformat

Included in:
Card::Format::Nest
Defined in:
lib/card/format/nest/subformat.rb

Instance Method Summary collapse

Instance Method Details

#depthObject



14
15
16
# File 'lib/card/format/nest/subformat.rb', line 14

def depth
  @depth ||= parent ? (parent.depth + 1) : 0
end

#field_subformat(field) ⇒ Object



26
27
28
29
# File 'lib/card/format/nest/subformat.rb', line 26

def field_subformat field
  field = card.cardname.field(field) unless field.is_a?(Card)
  subformat field
end

#focal?Boolean

meaning the current card is the requested card

Returns:

  • (Boolean)


22
23
24
# File 'lib/card/format/nest/subformat.rb', line 22

def focal? # meaning the current card is the requested card
  depth.zero?
end

#main?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/card/format/nest/subformat.rb', line 18

def main?
  depth.zero?
end

#rootObject



10
11
12
# File 'lib/card/format/nest/subformat.rb', line 10

def root
  @root ||= parent ? parent.root : self
end

#subformat(subcard) ⇒ Object



5
6
7
8
# File 'lib/card/format/nest/subformat.rb', line 5

def subformat subcard
  subcard = Card.fetch(subcard, new: {}) unless subcard.is_a?(Card)
  self.class.new subcard, parent: self, format_class: self.class, form: @form
end