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)


87
88
89
90
91
92
93
# File 'app/models/chart.rb', line 87

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



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

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

Instance Method Details

#as_json(options = {}) ⇒ Object



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

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

#assign_to(event) ⇒ Object

Raises:

  • (TypeError)


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

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



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

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

#create_first_sectionObject



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

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

#dup!Object



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

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

#has_paid_sections?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/models/chart.rb', line 95

def has_paid_sections?
  !self.sections.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



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

def update_attributes_from_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 ||= {}

  params_hash.fetch(:sections_attributes, []).each do |index, section_hash|
    new_price = Section.price_to_cents(section_hash['price'])
    section_hash['price'] = new_price
  end
  
  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



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

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

#widget_sectionsObject



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

def widget_sections
  self.sections.storefront.all
end