Class: Intent::Core::Inventory
- Inherits:
-
Object
- Object
- Intent::Core::Inventory
- Defined in:
- lib/intent/core.rb
Instance Attribute Summary collapse
-
#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
- #save! ⇒ Object
- #unassigned_boxes ⇒ Object
- #unassigned_folders ⇒ Object
- #units_of(noun) ⇒ Object
Constructor Details
Instance Attribute Details
#list ⇒ Object (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 |
#all ⇒ Object
62 63 64 |
# File 'lib/intent/core.rb', line 62 def all list.by_not_done end |
#assigned_boxes ⇒ Object
94 95 96 |
# File 'lib/intent/core.rb', line 94 def assigned_boxes all.filter { |i| i.[:is] == 'box' && i.projects.any? } end |
#assigned_folders ⇒ Object
82 83 84 |
# File 'lib/intent/core.rb', line 82 def assigned_folders all.filter { |i| i.[:is] == 'folder' && i.projects.any? } end |
#boxes ⇒ Object
86 87 88 |
# File 'lib/intent/core.rb', line 86 def boxes all.filter { |i| i.[: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.[:is] == 'folder' && i.[:id] == id } end |
#folders ⇒ Object
70 71 72 |
# File 'lib/intent/core.rb', line 70 def folders all.filter { |i| i.[: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.[:in] == id } end |
#save! ⇒ Object
123 124 125 |
# File 'lib/intent/core.rb', line 123 def save! @list.save! end |
#unassigned_boxes ⇒ Object
90 91 92 |
# File 'lib/intent/core.rb', line 90 def unassigned_boxes all.filter { |i| i.[:is] == 'box' && i.projects.empty? } end |
#unassigned_folders ⇒ Object
78 79 80 |
# File 'lib/intent/core.rb', line 78 def unassigned_folders all.filter { |i| i.[: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.[:is] == 'unit' && i.[:type] == noun.to_s } end |