Created
January 15, 2013 10:49
-
-
Save marcomoura/4537860 to your computer and use it in GitHub Desktop.
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
# model/order.rb | |
class Order | |
def items_format_type | |
items.group_by{ |order_item| order_item.item.format.type }.keys | |
end | |
end | |
# lib/order_resource.rb | |
class OrderResource | |
def self.create_on_external_service(order) | |
order_external = ServiceExternal::Order.new(order, messagem: OrderResource.channer_text(order)) | |
if order_external.save | |
order_external | |
else | |
raise InvalidOrderOnExternalService | |
end | |
end | |
def self.channel_text order | |
items_type = order.items_format_type.sort.join '_' | |
if items_type.match /paper/ | |
I18n.t "order.final.message.#{items_type}", delivery_date: order.delivery_date.strftime("%d/%m/%Y") | |
else | |
I18n.t "order.final.message.#{items_type}" | |
end | |
end | |
end | |
# locales/pt.yml | |
pt: | |
order: | |
final: | |
message: | |
paper: "bla bla bla #{delivery_date}" | |
pdf: etc etc etc | |
epub: tititi tititi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment