Class: Ticket::Glance

Inherits:
Object
  • Object
show all
Defined in:
app/models/ticket/glance.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Glance

Returns a new instance of Glance.



21
22
23
# File 'app/models/ticket/glance.rb', line 21

def initialize(parent)
  @parent = parent
end

Class Method Details

.report(reports) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/models/ticket/glance.rb', line 2

def self.report(reports)
  reports.each do |mthd, klass|
    # Define the getter method for this report
    class_eval(<<-EOS, __FILE__, __LINE__)
      def #{mthd}
        @#{mthd} ||= #{klass}.new(@parent)
      end
    EOS

    # Delegate methods to the created method
    delegate(*klass.reporting_methods, :prefix => true, :to => mthd)
  end
end

Instance Method Details

#as_json(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'app/models/ticket/glance.rb', line 25

def as_json(options ={})
  { :tickets => 
    { :comped => comped.total,
      :available => available.total,
      :sold => {
        :gross => sales.total
      }
    }
  }
end