Sha256: a70bb987c8013f815d8a282fa5a8155db487e1d1639313b1296e9fa7741e8c27

Contents?: true

Size: 846 Bytes

Versions: 32

Compression:

Stored size: 846 Bytes

Contents

class Ticket::Glance
  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

  report :available => Ticket::Reports::Available,
         :sold      => Ticket::Reports::Sold,
         :comped    => Ticket::Reports::Comped,
         :sales     => Ticket::Reports::Sales

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

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
artfully_ose-1.3.0.pre4 app/models/ticket/glance.rb
artfully_ose-1.3.0.pre3 app/models/ticket/glance.rb
artfully_ose-1.3.0.pre2 app/models/ticket/glance.rb
artfully_ose-1.3.0.pre1 app/models/ticket/glance.rb
artfully_ose-1.2.0 app/models/ticket/glance.rb
artfully_ose-1.2.0.beta.1 app/models/ticket/glance.rb
artfully_ose-1.2.0.alpha.2 app/models/ticket/glance.rb
artfully_ose-1.2.0.alpha.1 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.27 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.26 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.24 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.23 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.21 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.20 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.19 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.18 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.17 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.16 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.15 app/models/ticket/glance.rb
artfully_ose-1.2.0.pre.12 app/models/ticket/glance.rb