Module: MemberCardGenerator::InstanceMethods

Included in:
BlanksUsaIdc6
Defined in:
app/models/member_card_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#download_urlObject (readonly)

Returns the value of attribute download_url.



19
20
21
# File 'app/models/member_card_generator.rb', line 19

def download_url
  @download_url
end

#membersObject (readonly)

Returns the value of attribute members.



20
21
22
# File 'app/models/member_card_generator.rb', line 20

def members
  @members
end

Instance Method Details

#generateObject



31
32
33
# File 'app/models/member_card_generator.rb', line 31

def generate
  @download_url = pdf_generator.generate
end

#idObject



27
28
29
# File 'app/models/member_card_generator.rb', line 27

def id
  hash
end

#initialize(members, template = 'blanks_usa_idc6') ⇒ Object



22
23
24
25
# File 'app/models/member_card_generator.rb', line 22

def initialize(members, template='blanks_usa_idc6')
  @members = Array.wrap(members)
  validate_members!
end

#pdf_generatorObject



39
40
41
42
43
44
45
46
47
# File 'app/models/member_card_generator.rb', line 39

def pdf_generator
  @pdf_generator ||= begin
    PdfGeneration.new(self).tap do |p|
      p.pdf_options = {
        :page_size => 'Letter'
      }
    end
  end
end

#validate_members!Object

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
56
57
# File 'app/models/member_card_generator.rb', line 49

def validate_members!
  errors = []

  members.each_with_index do |member,index|
    errors << "    #{member.class} found at position #{index}" unless member.kind_of?(Member)
  end

  raise ArgumentError, "Only Member objects are supported for generating member cards:\n" + errors.join("\n") unless errors.empty?
end