Class: Ohbjects::OptionBuilder
- Inherits:
-
Object
- Object
- Ohbjects::OptionBuilder
- Extended by:
- Buildable
- Defined in:
- lib/ohbjects/options.rb
Constant Summary collapse
- METHOD_LOOKUP =
{ :optionRoot => :root, :strikePrice => :strike, :expDate => :expires, :bidSize => :bids, :askSize => :asks }
Instance Attribute Summary
Attributes included from Buildable
Class Method Summary collapse
Methods included from Buildable
build?, builds, extended, underscore
Class Method Details
.build(fragment) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ohbjects/options.rb', line 16 def build(fragment) put, call = Put.new, Call.new fragment.attributes.each do |key, attr| match = key.match(/^(call|put)?(.*)$/) option_type, method = match.captures method = METHOD_LOOKUP[method.to_sym] || underscore(method) setter = "#{method}=" value = attr.value if option_type option = option_type == "call" ? call : put option.send(setter, value) if option.respond_to?(setter) else [put, call].each do |option| option.send(setter, value) if option.respond_to?(setter) end end end [put, call] end |