Class: Comp

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
app/models/comp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(show, tickets_or_ids, recipient, benefactor) ⇒ Comp

tickets can be an array of tickets_ids or an array of tickets



12
13
14
15
16
17
18
# File 'app/models/comp.rb', line 12

def initialize(show, tickets_or_ids, recipient, benefactor)
  @show = show
  @tickets = []
  load_tickets(tickets_or_ids)
  @recipient = Person.find(recipient) unless recipient.blank?
  @benefactor = benefactor
end

Instance Attribute Details

#benefactorObject

Returns the value of attribute benefactor.



8
9
10
# File 'app/models/comp.rb', line 8

def benefactor
  @benefactor
end

#comped_countObject

Returns the value of attribute comped_count.



9
10
11
# File 'app/models/comp.rb', line 9

def comped_count
  @comped_count
end

#orderObject

Returns the value of attribute order.



8
9
10
# File 'app/models/comp.rb', line 8

def order
  @order
end

#reasonObject

Returns the value of attribute reason.



8
9
10
# File 'app/models/comp.rb', line 8

def reason
  @reason
end

#recipientObject

Returns the value of attribute recipient.



8
9
10
# File 'app/models/comp.rb', line 8

def recipient
  @recipient
end

#showObject

Returns the value of attribute show.



8
9
10
# File 'app/models/comp.rb', line 8

def show
  @show
end

#ticketsObject

Returns the value of attribute tickets.



8
9
10
# File 'app/models/comp.rb', line 8

def tickets
  @tickets
end

#uncomped_countObject

Returns the value of attribute uncomped_count.



9
10
11
# File 'app/models/comp.rb', line 9

def uncomped_count
  @uncomped_count
end

Instance Method Details

#has_recipient?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/comp.rb', line 36

def has_recipient?
  !recipient.blank?
end

#persisted?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/comp.rb', line 40

def persisted?
  false
end

#submitObject



44
45
46
47
48
49
50
# File 'app/models/comp.rb', line 44

def submit
  ActiveRecord::Base.transaction do
    create_order(@tickets, recipient, @benefactor)
    self.comped_count    = tickets.size
    self.uncomped_count  = 0
  end
end

#valid_recipient_and_benefactorObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/comp.rb', line 20

def valid_recipient_and_benefactor
  if @recipient.nil?
    errors.add(:base, "Please select a person to comp to or create a new person record")
    return
  end
  
  if @benefactor.nil?
    errors.add(:base, "Please select a benefactor")
    return
  end
  
  unless @benefactor.current_organization.eql? @recipient.organization
    errors.add(:base, "Recipient and benefactor are from different organizations")
  end
end