Last active
December 27, 2015 15:39
-
-
Save adamstrickland/7349109 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Product | |
field :traits, type: Array, default: [] | |
after_initialize :load_traits! | |
on_save :validates_methods | |
def load_traits! | |
self.traits.each do |trait| | |
self << class | |
self.send(:include, trait.camelize.constantize) | |
end | |
end | |
end | |
def validates_methods | |
[:settlement_periods].all?{ |m| self.respond_to?(m) } | |
end | |
end |
This file contains hidden or 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
Product.new(name: "Foo", traits: [:nymex_gas]) |
This file contains hidden or 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
module SettlementConcepts | |
module LastDayOfMonth | |
def settlement_periods(trade) | |
[(trade.tenor_start - 1.month).end_of_month] | |
end | |
end | |
module LastDayOfEveryMonthInTenor | |
def settlement_periods(trade) | |
(trade.tenor_start..trade.tenor_end).to_a.map(&:end_of_month).uniq | |
end | |
end | |
end |
This file contains hidden or 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 SettlementService | |
include Molecule::Services::Base | |
def call(trades, options=nil) | |
options ||= {} | |
Hash[*trades.map do |trade| | |
[trade, trade.settlement_periods] | |
end.flatten] | |
end | |
end |
This file contains hidden or 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 Trade | |
delegate :settlement_periods, to: :product | |
end |
This file contains hidden or 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
module NymexGas | |
include SettlementConcepts::LastDayOfMonth | |
include PositionConcepts::CalculateMonthly | |
include PositionConcepts::SomethingElse | |
end | |
module Power | |
include SettlementConcepts::DayOfFlow | |
include PositionConcepts::GroupByBlock | |
end | |
module Ercot | |
include PositionConcepts::FullDayBlock | |
include PositionConcepts::OnPeakAtEightInTheMorning | |
end | |
module PJM | |
include PositionConcepts::FullDayBlock | |
include PositionConcepts::OnPeakAtSevenInTheMorning | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment