collection_manager 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/collection.rb +2 -2
- data/lib/collection_manager.rb +48 -47
- data/lib/list.rb +25 -4
- data/lib/queue_list.rb +27 -0
- data/lib/stack.rb +3 -23
- metadata +3 -3
- data/lib/queue.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6ce6100e8c0936172096141fdcd9ec0561f33e5
|
4
|
+
data.tar.gz: b59ed22f5f785acf341a9a9df12598ed4c1ec4b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c931546fc9101a0b606c6d1e0f827665bb96336b3ca3601797eea6ff2e2b370c67255fa2a6c9dc1642ea932f6da702253602c86067784065712e4036ea559b96
|
7
|
+
data.tar.gz: af63f4e37f5f24eeadd469dfea03a6d8b38be3180b8f88d122a9f26c77904a6d24765a56dd2bb41a5c28d4ee244a68dd87268f606e56dea193388eaba526dc75
|
data/lib/collection.rb
CHANGED
data/lib/collection_manager.rb
CHANGED
@@ -1,58 +1,59 @@
|
|
1
1
|
require_relative 'collection'
|
2
2
|
require_relative 'stack'
|
3
|
+
require_relative 'queue_list'
|
3
4
|
##
|
4
5
|
# Collection Manager Class to manage collections
|
5
6
|
|
6
7
|
class CollectionManager
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def initialize
|
9
|
+
@current_id = 0;
|
10
|
+
@collections = Hash.new
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
##
|
14
|
+
# Adds a new collection to the Hash object
|
15
|
+
#
|
16
|
+
# Example:
|
17
|
+
# >> cm = CollectionManager.new
|
18
|
+
# >> cm.add(Stack.new)
|
19
|
+
#
|
20
|
+
# Arguments:
|
21
|
+
# a collection object, eg. Stack or Queue
|
22
|
+
#
|
23
|
+
def add(collection)
|
24
|
+
@current_id += 1
|
25
|
+
@collections[@current_id] = collection
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
##
|
29
|
+
# Deletes a collection from the Hash object
|
30
|
+
#
|
31
|
+
# Example:
|
32
|
+
# >> cm.delete(1)
|
33
|
+
#
|
34
|
+
# Arguments:
|
35
|
+
# id of the collection
|
36
|
+
#
|
37
|
+
def delete(id)
|
38
|
+
@collections.delete(id)
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
41
|
+
##
|
42
|
+
# Returns a collection form the Hash id with key as id
|
43
|
+
#
|
44
|
+
# Example:
|
45
|
+
# >> cm.find(1)
|
46
|
+
# => value at key 1 in the Hash object
|
47
|
+
# Arguments:
|
48
|
+
# id of the collection
|
49
|
+
#
|
50
|
+
def find(id)
|
51
|
+
@collections[id]
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
##
|
55
|
+
# Returns all the collections
|
56
|
+
def all
|
57
|
+
@collections
|
58
|
+
end
|
58
59
|
end
|
data/lib/list.rb
CHANGED
@@ -1,8 +1,29 @@
|
|
1
1
|
require_relative 'collection'
|
2
2
|
|
3
|
+
##
|
4
|
+
# List class implementing a list collection
|
5
|
+
|
3
6
|
class List < Collection
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
def initialize(size = nil)
|
8
|
+
super()
|
9
|
+
@list = Array.new
|
10
|
+
@size = size
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# This method appends an element to the list
|
15
|
+
|
16
|
+
def push(object)
|
17
|
+
if(@size && @list.length >= @size)
|
18
|
+
puts "Stack full!"
|
19
|
+
else
|
20
|
+
@list.push(object)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Defines to string method
|
26
|
+
def to_s
|
27
|
+
@list
|
28
|
+
end
|
8
29
|
end
|
data/lib/queue_list.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'list'
|
2
|
+
|
3
|
+
##
|
4
|
+
# QueueList class implementing a typical Queue data structure
|
5
|
+
|
6
|
+
class QueueList < List
|
7
|
+
def initialize(size = nil)
|
8
|
+
super(size)
|
9
|
+
end
|
10
|
+
|
11
|
+
##
|
12
|
+
# This method implements remove functionality of a Queue (FIFO)
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
# >> s = QueueList.new
|
16
|
+
# >> s.push("else")
|
17
|
+
# >> s.push("something")
|
18
|
+
# >> s.remove()
|
19
|
+
# => "else"
|
20
|
+
def remove()
|
21
|
+
if(@list.length == 0)
|
22
|
+
puts "Queue empty!"
|
23
|
+
else
|
24
|
+
@list.shift
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/stack.rb
CHANGED
@@ -5,31 +5,15 @@ require_relative 'list'
|
|
5
5
|
|
6
6
|
class Stack < List
|
7
7
|
def initialize(size = nil)
|
8
|
-
super()
|
9
|
-
@size = size
|
8
|
+
super(size)
|
10
9
|
end
|
11
10
|
|
12
11
|
##
|
13
|
-
# This method implements
|
14
|
-
#
|
15
|
-
# Example:
|
16
|
-
# >> s = Stack.new
|
17
|
-
# >> s.push("something")
|
18
|
-
# >> s.push(20)
|
19
|
-
|
20
|
-
def push(object)
|
21
|
-
if(@size && @list.length >= @size)
|
22
|
-
puts "Stack full!"
|
23
|
-
else
|
24
|
-
@list.push(object)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# This method implements pop functionality of a stack
|
12
|
+
# This method implements pop functionality of a stack (LIFO)
|
30
13
|
#
|
31
14
|
# Example:
|
32
15
|
# >> s = Stack.new
|
16
|
+
# >> s.push("else")
|
33
17
|
# >> s.push("something")
|
34
18
|
# >> s.pop()
|
35
19
|
# => "something"
|
@@ -40,8 +24,4 @@ class Stack < List
|
|
40
24
|
@list.pop
|
41
25
|
end
|
42
26
|
end
|
43
|
-
|
44
|
-
def to_s
|
45
|
-
@list
|
46
|
-
end
|
47
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collection_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shirish Parsekar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: collection Manager for managing a collection of objects
|
14
14
|
email: shirish.parsekar@weboniselab.com
|
@@ -19,7 +19,7 @@ files:
|
|
19
19
|
- lib/collection.rb
|
20
20
|
- lib/collection_manager.rb
|
21
21
|
- lib/list.rb
|
22
|
-
- lib/
|
22
|
+
- lib/queue_list.rb
|
23
23
|
- lib/stack.rb
|
24
24
|
homepage: http://rubygems.org/gems/collection_manager
|
25
25
|
licenses:
|
data/lib/queue.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require_relative 'list'
|
2
|
-
|
3
|
-
class Queue < List
|
4
|
-
def initialize(size = nil)
|
5
|
-
super()
|
6
|
-
@size = size
|
7
|
-
end
|
8
|
-
|
9
|
-
def push(object)
|
10
|
-
if(@list.length < @size)
|
11
|
-
@list.push(object)
|
12
|
-
else
|
13
|
-
puts "Queue full!"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def remove()
|
18
|
-
if(@list.length == 0)
|
19
|
-
puts "Queue empty!"
|
20
|
-
else
|
21
|
-
@list.pop
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_s
|
26
|
-
@list
|
27
|
-
end
|
28
|
-
end
|