Skip to content

Instantly share code, notes, and snippets.

@adamstrickland
Last active December 20, 2015 10:19
Show Gist options
  • Save adamstrickland/6114124 to your computer and use it in GitHub Desktop.
Save adamstrickland/6114124 to your computer and use it in GitHub Desktop.
ng_products = Product.where(:"commodity.name" => /ng/i).each do |p|
p.expiry_rule = :preceeding_weekday
end
module Expiry
def preceeding_weekday(trade)
[-5..-1].map{ |i| trade.tenor_start + i.days }.select(&:nerc_weekday?).last
end
# other expiry rules
end
class Product
include Expiry
def expiry
self.send(self.expiry_rule, self)
end
end
class Trade
delegate :expiry, to: :product
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment