Class: Section

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Ticket::Foundry
Defined in:
app/models/section.rb

Direct Known Subclasses

DiscountSection

Constant Summary collapse

@@channels =

Each channel needs its own boolean column in the sections table.

{ :storefront => "S", :box_office => "B"}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ticket::Foundry

#build_tickets, #create_tickets, #foundry_template

Class Method Details

.price_to_cents(price_in_dollars) ⇒ Object



38
39
40
# File 'app/models/section.rb', line 38

def self.price_to_cents(price_in_dollars)
  (price_in_dollars.to_f * 100).to_i
end

Instance Method Details

#as_json(options = {}) ⇒ Object



67
68
69
70
# File 'app/models/section.rb', line 67

def as_json(options = {})
  options ||= {}
  super(:methods => :summary).merge(options)
end

#availableObject



59
60
61
# File 'app/models/section.rb', line 59

def available
  Ticket.on_sale.where(:section_id => self.id).where(:cart_id => nil).count
end

#channelsObject



30
31
32
# File 'app/models/section.rb', line 30

def channels
  @@channels
end

#dup!Object



34
35
36
# File 'app/models/section.rb', line 34

def dup!
  Section.new(self.attributes.reject { |key, value| key == 'id' })
end

#put_on_sale(qty = 0) ⇒ Object



47
48
49
50
51
# File 'app/models/section.rb', line 47

def put_on_sale(qty = 0)
  tickets.off_sale.limit(qty).each do |t|
    t.put_on_sale
  end
end

#summarizeObject



42
43
44
45
# File 'app/models/section.rb', line 42

def summarize
  tickets = Ticket.where(:section_id => id)
  @summary = SectionSummary.for_tickets(tickets)
end

#summaryObject



63
64
65
# File 'app/models/section.rb', line 63

def summary
  @summary || summarize
end

#take_off_sale(qty = 0) ⇒ Object



53
54
55
56
57
# File 'app/models/section.rb', line 53

def take_off_sale(qty = 0)
  tickets.on_sale.limit(qty).each do |t|
    t.take_off_sale
  end
end