Class: Intent::Core::Inventory

Inherits:
Object
  • Object
show all
Defined in:
lib/intent/core/inventory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_path) ⇒ Inventory

Returns a new instance of Inventory.



7
8
9
10
# File 'lib/intent/core/inventory.rb', line 7

def initialize(db_path)
  @ledger_path = db_path
  @list = List.new(db_path)
end

Instance Attribute Details

#ledger_pathObject (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

#listObject (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

#allObject



12
13
14
# File 'lib/intent/core/inventory.rb', line 12

def all
  list.by_not_done
end

#assigned_boxesObject



44
45
46
# File 'lib/intent/core/inventory.rb', line 44

def assigned_boxes
  all.filter { |i| i.tags[:is] == 'box' && i.projects.any? }
end

#assigned_foldersObject



32
33
34
# File 'lib/intent/core/inventory.rb', line 32

def assigned_folders
  all.filter { |i| i.tags[:is] == 'folder' && i.projects.any? }
end

#boxesObject



36
37
38
# File 'lib/intent/core/inventory.rb', line 36

def boxes
  all.filter { |i| i.tags[: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.tags[:is] == 'folder' && i.tags[:id] == id }
end

#foldersObject



20
21
22
# File 'lib/intent/core/inventory.rb', line 20

def folders
  all.filter { |i| i.tags[: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.tags[:in] == id }
end

#local_computer_idObject



52
53
54
# File 'lib/intent/core/inventory.rb', line 52

def local_computer_id
  all.find { |i| i.tags[:is] == 'computer' && i.tags[:serial] == Env.computer_serial }.tags[: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_boxesObject



40
41
42
# File 'lib/intent/core/inventory.rb', line 40

def unassigned_boxes
  all.filter { |i| i.tags[:is] == 'box' && i.projects.empty? }
end

#unassigned_foldersObject



28
29
30
# File 'lib/intent/core/inventory.rb', line 28

def unassigned_folders
  all.filter { |i| i.tags[: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.tags[:is] == 'unit' && i.tags[:type] == noun.to_s }
end