Sha256: b8ba1c84d30dc693499c305d31867563eb66bd9f4d355a1396c95ea6074163ef

Contents?: true

Size: 1.22 KB

Versions: 20

Compression:

Stored size: 1.22 KB

Contents

#
# This needs to be refactored to be less database intensive
#
module Ticket::Reports
  class Base
    def initialize(parent)
      @parent = parent
    end

    def self.reporting_methods
      self.public_instance_methods - Object.public_instance_methods
    end

    private

    def parent
      @parent
    end

    def tickets
      parent.send(:tickets)
    end
  end

  class Available < Base
    def total
      tickets.select(&:on_sale?).length
    end
  end

  class Sold < Base
    def total
      tickets.select(&:sold?).length
    end

    def today
      tickets.sold_after(Time.now.beginning_of_day).count
    end

    def played
      tickets.sold.played.count
    end
  end

  class Comped < Base
    def total
      tickets.select(&:comped?).length
    end

    def today
      tickets.comped.sold_after(Time.now.beginning_of_day).count
    end

    def played
      tickets.comped.played.count
    end
  end

  class Sales < Base
    def total
      tickets.sold.sum(:sold_price)
    end

    def today
      tickets.sold_after(Time.now.beginning_of_day).sum(:sold_price)
    end

    def played
      tickets.sold.played.sum(:sold_price)
    end

    def advance
      tickets.sold.unplayed.sum(:sold_price)
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.21 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.20 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.19 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.18 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.17 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.16 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.15 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.12 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.11 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.10 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.9 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.8 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.7 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.6 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.5 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.4 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.3 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.2 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre.1 app/models/ticket/reports.rb
artfully_ose-1.2.0.pre app/models/ticket/reports.rb