Class: Intent::Core::Inventory
- Inherits:
-
Object
- Object
- Intent::Core::Inventory
- Defined in:
- lib/intent/core/inventory.rb
Instance Attribute Summary collapse
-
#ledger_path ⇒ Object
readonly
Returns the value of attribute ledger_path.
-
#list ⇒ Object
readonly
Returns the value of attribute list.
Instance Method Summary collapse
- #add_box!(description, id, sku) ⇒ Object
- #add_folder!(description, id, sku, box = nil) ⇒ Object
- #add_item!(description, id, type, sku, box = nil) ⇒ Object
- #add_unit!(description, type, sku) ⇒ Object
- #all ⇒ Object
- #assigned_boxes ⇒ Object
- #assigned_folders ⇒ Object
- #boxes ⇒ Object
- #folder_by_id(id) ⇒ Object
- #folders ⇒ Object
-
#initialize(db_path) ⇒ Inventory
constructor
A new instance of Inventory.
- #items_in(id) ⇒ Object
- #local_computer_id ⇒ Object
- #save! ⇒ Object
- #sync! ⇒ Object
- #unassigned_boxes ⇒ Object
- #unassigned_folders ⇒ Object
- #units_of(noun) ⇒ Object
Constructor Details
Instance Attribute Details
#ledger_path ⇒ Object (readonly)
Returns the value of attribute ledger_path.
5 6 7 |
# File 'lib/intent/core/inventory.rb', line 5 def ledger_path @ledger_path end |
#list ⇒ Object (readonly)
Returns the value of attribute list.
4 5 6 |
# File 'lib/intent/core/inventory.rb', line 4 def list @list end |
Instance Method Details
#add_box!(description, id, sku) ⇒ Object
73 74 75 |
# File 'lib/intent/core/inventory.rb', line 73 def add_box!(description, id, sku) add_item!(description, id, :box, sku) end |
#add_folder!(description, id, sku, box = nil) ⇒ Object
69 70 71 |
# File 'lib/intent/core/inventory.rb', line 69 def add_folder!(description, id, sku, box=nil) add_item!(description, id, :folder, sku, box) end |
#add_item!(description, id, type, sku, box = nil) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/intent/core/inventory.rb', line 62 def add_item!(description, id, type, sku, box=nil) description << " in:#{box}" unless box.nil? record = Record.new("#{Date.today} #{description} id:#{id} is:#{type} sku:#{sku}") @list.append(record) @list.save! end |
#add_unit!(description, type, sku) ⇒ Object
56 57 58 59 60 |
# File 'lib/intent/core/inventory.rb', line 56 def add_unit!(description, type, sku) record = Record.new("#{Date.today} #{description} is:unit type:#{type} sku:#{sku}") @list.append(record) @list.save! end |
#all ⇒ Object
12 13 14 |
# File 'lib/intent/core/inventory.rb', line 12 def all list.by_not_done end |
#assigned_boxes ⇒ Object
44 45 46 |
# File 'lib/intent/core/inventory.rb', line 44 def assigned_boxes all.filter { |i| i.[:is] == 'box' && i.projects.any? } end |
#assigned_folders ⇒ Object
32 33 34 |
# File 'lib/intent/core/inventory.rb', line 32 def assigned_folders all.filter { |i| i.[:is] == 'folder' && i.projects.any? } end |
#boxes ⇒ Object
36 37 38 |
# File 'lib/intent/core/inventory.rb', line 36 def boxes all.filter { |i| i.[:is] == 'box' } end |
#folder_by_id(id) ⇒ Object
16 17 18 |
# File 'lib/intent/core/inventory.rb', line 16 def folder_by_id(id) all.find { |i| i.[:is] == 'folder' && i.[:id] == id } end |
#folders ⇒ Object
20 21 22 |
# File 'lib/intent/core/inventory.rb', line 20 def folders all.filter { |i| i.[:is] == 'folder' } end |
#items_in(id) ⇒ Object
24 25 26 |
# File 'lib/intent/core/inventory.rb', line 24 def items_in(id) all.filter { |i| i.[:in] == id } end |
#local_computer_id ⇒ Object
52 53 54 |
# File 'lib/intent/core/inventory.rb', line 52 def local_computer_id all.find { |i| i.[:is] == 'computer' && i.[:serial] == Env.computer_serial }.[:id] end |
#save! ⇒ Object
77 78 79 |
# File 'lib/intent/core/inventory.rb', line 77 def save! @list.save! end |
#sync! ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/intent/core/inventory.rb', line 81 def sync! ledger_file = File.basename(ledger_path) if repo.status.changed?(ledger_file) repo.add(ledger_file) repo.commit("Synchronizing inventory [#{Time.new}]") repo.push true # Result:OK else false # Result::NO_CHANGES end end |
#unassigned_boxes ⇒ Object
40 41 42 |
# File 'lib/intent/core/inventory.rb', line 40 def unassigned_boxes all.filter { |i| i.[:is] == 'box' && i.projects.empty? } end |
#unassigned_folders ⇒ Object
28 29 30 |
# File 'lib/intent/core/inventory.rb', line 28 def unassigned_folders all.filter { |i| i.[:is] == 'folder' && i.projects.empty? } end |
#units_of(noun) ⇒ Object
48 49 50 |
# File 'lib/intent/core/inventory.rb', line 48 def units_of(noun) all.filter { |i| i.[:is] == 'unit' && i.[:type] == noun.to_s } end |