Last active
August 29, 2015 14:10
-
-
Save joshuacronemeyer/7ce64fea1479087f71fb to your computer and use it in GitHub Desktop.
Pseudocode imagining how i might model the problem of creating CSV for creating willcall lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# understands how to display a csv row describing an addon purchase. | |
class AddonCsvRow | |
def initialize(addon, order) | |
@addon = addon | |
@order = order | |
end | |
def to_csv | |
"#{order.box_office_last_name}, #{order.box_office_first_name}, etc, etc" | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# understands how to display a csv describing an item sold for a particular tour date. | |
class BoxOfficeList | |
ADDON_TYPE = :addon | |
TICKET_TYPE = :ticket | |
def initialize(occurrence, type, object_id) | |
@occurrnece = occurrence | |
@type = type #TODO raise ArgumentError if unknown type | |
@object_id = object_id | |
end | |
def to_csv | |
csv = csv_header | |
csv << csv_blank_line | |
csv << csv_row_header | |
csv << if @type == ADDON_TYPE | |
addon = AddonItem.find(object_id) | |
orders = Core::Order.where(addon_id: object_id).order_by_box_office_name | |
orders.map{|order| AddonCsvRow.new(addon, order).to_csv} | |
elsif @type == TICKET_TYPE | |
ticket = UserCreated::TicketGroup.find(object_id) | |
orders = Core::Order.where(ticket_group_id: object_id).order_by_box_office_name | |
orders.map{|order| TicketCsvRow.new(addon, order).to_csv} | |
end | |
csv << csv_footer | |
end | |
def to_s | |
if @type == ADDON_TYPE | |
AddonItem.find(object_id).name | |
elsif @type == TICKET_TYPE | |
UserCreated::TicketGroup.find(object_id).name | |
end | |
end | |
def csv_header | |
#create csv header based on occurrence, type, object | |
end | |
def csv_row_header | |
#create row header based on type | |
end | |
def csv_blank_line | |
",,,,,\n" | |
end | |
def csv_footer | |
#footer data string | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dl class="box_office_lists"> | |
<% @box_office_lists.each_list do |box_office_list| %> | |
<dt><%= box_office_list.to_s %></dt><dd><%= link_to box_office_list %></dd> | |
<%> end <%> | |
</dl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BoxOfficeLists | |
def initialize(occurrence) | |
@occurrence = occurrence | |
end | |
def each_list do | |
ticket_groups = @occurrence.user_created_ticket_groups_with_sales | |
addons = @occurrence.addon_items_with_sales | |
(ticket_groups + addons).each do |item| | |
type = item.kind_of?(UserCreated::TicketGroup) ? BoxOfficeList::TICKET_TYPE : BoxOfficeList::AddonType | |
yield(BoxOfficeList.new(@occurrence, type, item.id)) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BoxOfficeListController < ApplicationController | |
def show | |
@box_office_lists = BoxOfficeLists.new(params[:occurrence_id]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# understands how to display a csv row describing a ticket purchase. | |
class TicketCsvRow | |
def initialize(ticket, order) | |
@ticket = ticket | |
@order = order | |
end | |
def to_csv | |
"#{order.box_office_last_name}, #{order.box_office_first_name}, etc, etc" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment