Module: Card::Subcards::All

Included in:
Card
Defined in:
card/lib/card/subcards/all.rb

Overview

subcard-related Card instance methods

Instance Method Summary collapse

Instance Method Details

#drop_field(name_or_card) ⇒ Object



53
54
55
# File 'card/lib/card/subcards/all.rb', line 53

def drop_field name_or_card
  subcards.remove_field name_or_card
end

#drop_subcard(name_or_card) ⇒ Object



49
50
51
# File 'card/lib/card/subcards/all.rb', line 49

def drop_subcard name_or_card
  subcards.remove name_or_card
end

#field(field_name, args = {}) ⇒ Object



32
33
34
35
36
37
38
39
# File 'card/lib/card/subcards/all.rb', line 32

def field field_name, args={}
  if (sf = subcards.field field_name)
    sf.assign_attributes args
    sf
  else
    subcards.add_field field_name, args
  end
end

#field?(tag) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'card/lib/card/subcards/all.rb', line 45

def field? tag
  fetch(tag) || subcards.field(tag).present?
end

#field_content(field_name) ⇒ Object



41
42
43
# File 'card/lib/card/subcards/all.rb', line 41

def field_content field_name
  subcards.field(field_name)&.content
end

#handle_subcard_errorsObject



57
58
59
60
61
62
63
64
# File 'card/lib/card/subcards/all.rb', line 57

def handle_subcard_errors
  subcards.each do |subcard|
    subcard.errors.each do |error|
      subcard_error subcard, error
    end
    subcard.errors.clear
  end
end

#subcard(card_name, args = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'card/lib/card/subcards/all.rb', line 15

def subcard card_name, args={}
  if (sc = subcards.card card_name)
    sc.assign_attributes args
    sc
  else
    subcards.add card_name, args
  end
end

#subcard?(card_name) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'card/lib/card/subcards/all.rb', line 28

def subcard? card_name
  subcards.card(card_name).present?
end

#subcard_content(card_name) ⇒ Object



24
25
26
# File 'card/lib/card/subcards/all.rb', line 24

def subcard_content card_name
  subcards.card(card_name)&.content
end

#subcardsObject



7
8
9
# File 'card/lib/card/subcards/all.rb', line 7

def subcards
  @subcards ||= Card::Subcards.new self
end

#subcards?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'card/lib/card/subcards/all.rb', line 11

def subcards?
  subcards.present?
end