Module: IB::BaseProperties

Extended by:
ActiveSupport::Concern
Included in:
Bar, ComboLeg, Contract, ContractDetail, Execution, Order, OrderState, Underlying
Defined in:
lib/ib/base_properties.rb

Overview

Module adds prop Macro and

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

Default Model comparison



44
45
46
47
# File 'lib/ib/base_properties.rb', line 44

def == other
  content_attributes.inject(true) { |res, (attr, value)| res && other.send(attr) == value } &&
    other.content_attributes.inject(true) { |res, (attr, value)| res && send(attr) == value }
end

#content_attributesObject

Comparison support



27
28
29
30
31
32
33
# File 'lib/ib/base_properties.rb', line 27

def content_attributes
  HashWithIndifferentAccess[attributes.reject do |(attr, _)|
                              attr.to_s =~ /(_count)$/ ||
                                [:created_at, :updated_at, :type,
                                 :id, :order_id, :contract_id].include?(attr.to_sym)
  end]
end

#default_attributesObject



11
12
13
14
15
# File 'lib/ib/base_properties.rb', line 11

def default_attributes
  {:created_at => Time.now,
   :updated_at => Time.now,
   }
end

#to_humanObject

Default presentation



20
21
22
23
24
# File 'lib/ib/base_properties.rb', line 20

def to_human
  "<#{self.class.to_s.demodulize}: " + attributes.map do |attr, value|
    "#{attr}: #{value}" unless value.nil?
  end.compact.sort.join(' ') + ">"
end

#update_missing(attrs) ⇒ Object

Update nil attributes from given Hash or model



36
37
38
39
40
41
# File 'lib/ib/base_properties.rb', line 36

def update_missing attrs
  attrs = attrs.content_attributes unless attrs.kind_of?(Hash)

  attrs.each { |attr, val| send "#{attr}=", val if send(attr).blank? }
  self # for chaining
end