Class: Chart

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ticket::Foundry

#build_tickets, #create_tickets, #foundry_template

Instance Attribute Details

#skip_create_first_sectionObject

Returns the value of attribute skip_create_first_section.



4
5
6
# File 'app/models/chart.rb', line 4

def skip_create_first_section
  @skip_create_first_section
end

Class Method Details

.default_chart_for(event) ⇒ Object

Raises:

  • (TypeError)


94
95
96
97
98
99
100
# File 'app/models/chart.rb', line 94

def self.default_chart_for(event)
  raise TypeError, "Expecting an Event" unless event.kind_of? Event
  @chart = self.new
  @chart.name = self.get_default_name(event.name)
  @chart.event_id = event.id
  @chart
end

.get_default_name(prefix) ⇒ Object



90
91
92
# File 'app/models/chart.rb', line 90

def self.get_default_name(prefix)
  prefix + ', default chart'
end

.polish_params(params_hash = {}) ⇒ Object

Any pre-processing of the chart_params (like manipulating the price) can be done here



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/chart.rb', line 50

def self.polish_params(params_hash = {})
  #
  # HACK: The move to bootstrap left us with currency submission in the form os "DD.CC" which 
  # Artfully interpreted as DD.00.  
  # This hack converts DD.CC to DDCC
  #  
  params_hash.fetch(:sections_attributes, []).each do |index,section_hash|
    section_hash.fetch(:ticket_types_attributes, []).each do |index, ticket_type_hash|
      new_price = TicketType.price_to_cents(ticket_type_hash['price'])
      ticket_type_hash['price'] = new_price
    end
  end

  params_hash
end

Instance Method Details

#as_json(options = {}) ⇒ Object



19
20
21
22
23
# File 'app/models/chart.rb', line 19

def as_json(options = {})
  h = super(options)
  h[:sections]   = sections
  h
end

#assign_to(event) ⇒ Object

Raises:

  • (TypeError)


83
84
85
86
87
88
# File 'app/models/chart.rb', line 83

def assign_to(event)
  raise TypeError, "Expecting an Event" unless event.kind_of? Event
  assigned = self.dup!
  assigned.event = event
  assigned.save
end

#copy!Object

copy! is when they’re editing charts and want to create a copy of this chart to modify further (weekday and weekend charts) This method will copy chart.is_template



32
33
34
# File 'app/models/chart.rb', line 32

def copy!
  duplicate(:without => "id", :with => { :name => "#{name} (Copy)" })
end

#create_first_sectionObject



40
41
42
43
44
45
# File 'app/models/chart.rb', line 40

def create_first_section
  if sections.empty?
    self.sections.build({ :name => "General Admission",
                          :capacity => 0 }).save
  end
end

#dup!Object



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

def dup!
  duplicate(:without => "id", :with => { :is_template => false })
end

#has_paid_sections?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'app/models/chart.rb', line 102

def has_paid_sections?
  !self.ticket_types.drop_while{|s| s.price.to_i == 0}.empty?
end

#update_attributes_from_params(params_hash = {}) ⇒ Object

params_hash is the params with :section_attributes as a key.

This is how they’re submitted from the ticket types form



70
71
72
73
# File 'app/models/chart.rb', line 70

def update_attributes_from_params(params_hash = {})
  update_attributes(params_hash)
  upgrade_event
end

#upgrade_eventObject

If this is a free event, and they’ve specified prices on this chart, then upgrade to a paid event



76
77
78
79
80
81
# File 'app/models/chart.rb', line 76

def upgrade_event
  if !event.nil? && event.free? && has_paid_sections?
    event.is_free = false
    event.save
  end    
end

#widget_sectionsObject



25
26
27
# File 'app/models/chart.rb', line 25

def widget_sections
  self.sections.storefront.all
end