Class: Stock::HoldingEntry

Inherits:
Ohm::Model
  • Object
show all
Includes:
Ohm::Callbacks, Ohm::Struct
Defined in:
lib/porp/stock/holding.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (HoldingEntry) initialize(attrs = {})

A new instance of HoldingEntry



146
147
148
149
150
151
152
153
# File 'lib/porp/stock/holding.rb', line 146

def initialize(attrs = {})
  attrs.delete(:ctime)  # ctime can never be overruled)
  super(attrs)
#      binding.pry
  self.ctime ||= Time.now.to_f
  self.amount_in ||= Amount.new(0, 0)
  self.amount_out ||= Amount.new(0, self.amount_in.ucost)
end

Class Method Details

+ (Object) const_missing(name)



172
173
174
# File 'lib/porp/stock/holding.rb', line 172

def self.const_missing(name)
  Stock.const_get(name)
end

Instance Method Details

- (Object) amount_remaining

Returns the amount remaining as an Amount struct The unit cost can only ever be as per amount_in



157
158
159
# File 'lib/porp/stock/holding.rb', line 157

def amount_remaining
  Amount.new(Integer(amount_in.qty) - Integer(amount_out.qty), amount_in.ucost)
end

- (Boolean) eol?

Returns whether the Holding is end of life. True when quantity is zero (and Movements > 0?)

Returns:

  • (Boolean)


163
164
165
# File 'lib/porp/stock/holding.rb', line 163

def eol?
  !self.amount_in.nil? &&self.amount_in.int_qty == self.amount_out.int_qty
end

- (Object) mtime_update

Updates the mtime attribute to the current time



168
169
170
# File 'lib/porp/stock/holding.rb', line 168

def mtime_update
  self.mtime = Time.now.to_f
end