Class: Intent::Core::Inventory

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_path) ⇒ Inventory

Returns a new instance of Inventory.



58
59
60
# File 'lib/intent/core.rb', line 58

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

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



56
57
58
# File 'lib/intent/core.rb', line 56

def list
  @list
end

Instance Method Details

#add_box!(description, id, sku) ⇒ Object



119
120
121
# File 'lib/intent/core.rb', line 119

def add_box!(description, id, sku)
  add_item!(description, id, :box, sku)
end

#add_folder!(description, id, sku, box = nil) ⇒ Object



115
116
117
# File 'lib/intent/core.rb', line 115

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



108
109
110
111
112
113
# File 'lib/intent/core.rb', line 108

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



102
103
104
105
106
# File 'lib/intent/core.rb', line 102

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



62
63
64
# File 'lib/intent/core.rb', line 62

def all
  list.by_not_done
end

#assigned_boxesObject



94
95
96
# File 'lib/intent/core.rb', line 94

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

#assigned_foldersObject



82
83
84
# File 'lib/intent/core.rb', line 82

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

#boxesObject



86
87
88
# File 'lib/intent/core.rb', line 86

def boxes
  all.filter { |i| i.tags[:is] == 'box' }
end

#folder_by_id(id) ⇒ Object



66
67
68
# File 'lib/intent/core.rb', line 66

def folder_by_id(id)
  all.find { |i| i.tags[:is] == 'folder' && i.tags[:id] == id }
end

#foldersObject



70
71
72
# File 'lib/intent/core.rb', line 70

def folders
  all.filter { |i| i.tags[:is] == 'folder' }
end

#items_in(id) ⇒ Object



74
75
76
# File 'lib/intent/core.rb', line 74

def items_in(id)
  all.filter { |i| i.tags[:in] == id }
end

#save!Object



123
124
125
# File 'lib/intent/core.rb', line 123

def save!
  @list.save!
end

#unassigned_boxesObject



90
91
92
# File 'lib/intent/core.rb', line 90

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

#unassigned_foldersObject



78
79
80
# File 'lib/intent/core.rb', line 78

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

#units_of(noun) ⇒ Object



98
99
100
# File 'lib/intent/core.rb', line 98

def units_of(noun)
  all.filter { |i| i.tags[:is] == 'unit' && i.tags[:type] == noun.to_s }
end