Class: Stock

Inherits:
Object
  • Object
show all
Defined in:
lib/porp/stock.rb,
lib/porp/stock/status.rb,
lib/porp/stock/holder.rb,
lib/porp/stock/entity.rb,
lib/porp/stock/holding.rb,
lib/porp/stock/director.rb,
lib/porp/stock/movement.rb,
lib/porp/stock/sourcedest.rb,
lib/porp/stock/movementtarget.rb

Overview

Porp - The Prototype Open Retail Platform

Copyright (c) 2010 Phil Stewart

License: MIT (see LICENSE file)

Defined Under Namespace

Classes: Director, Entity, Holder, Holding, HoldingEntry, MiscTarget, Movement, MovementTarget, NullTarget, SourceDest, Status

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Stock) initialize(entity = nil)

A new instance of Stock



56
57
58
# File 'lib/porp/stock.rb', line 56

def initialize(entity = nil)
  @entity = entity
end

Instance Attribute Details

- (Object) entity (readonly)

Returns the value of attribute entity



20
21
22
# File 'lib/porp/stock.rb', line 20

def entity
  @entity
end

Class Method Details

+ (Object) [](id)

A Stock instance for the stock entity identified by id

Returns:

  • A Stock instance for the stock entity identified by id



23
24
25
26
27
28
29
30
# File 'lib/porp/stock.rb', line 23

def self.[](id)
  entity = Entity[id]
  if !entity.nil?
    self.new(Entity[id])
  else
    nil
  end
end

+ (Stock) create(description = "", opts = {})

Creates a new item of stock, including the entity and all holdings, ensuring all dependencies are met i.e. all targets, holders, and statuses

Parameters:

  • description (String) (defaults to: "")

    description of the stock

  • opts (Hash) (defaults to: {})

    stock creation options

Returns:

  • (Stock)

    the newly created item of stock

Raises:



49
50
51
52
53
54
# File 'lib/porp/stock.rb', line 49

def self.create(description = "", opts = {})
  raise Orp::NoHoldersSpecified if opts[:holders].nil?
  raise Orp::NoStatusesSpecified if opts[:statuses].nil?

  self.new(Director.build_from_options(description, opts))
end

+ (Object) find_by_plu(plu_value)

Find an item of stock by PLU



33
34
35
36
37
38
39
40
# File 'lib/porp/stock.rb', line 33

def self.find_by_plu(plu_value)
  entity = Entity.find_by_plu(plu_value)
  if !entity.nil?
    self.new(entity)
  else
    nil
  end
end

Instance Method Details

- (Object) id

The ID of the associated entity

Returns:

  • The ID of the associated entity



61
62
63
# File 'lib/porp/stock.rb', line 61

def id
  entity.id
end