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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 689897b22b48c70e95a880d4da99153abd5d7603
4
- data.tar.gz: 30df932ef5b124714821fef674c2f78079851f4b
3
+ metadata.gz: f6ce6100e8c0936172096141fdcd9ec0561f33e5
4
+ data.tar.gz: b59ed22f5f785acf341a9a9df12598ed4c1ec4b8
5
5
  SHA512:
6
- metadata.gz: 95ad51fa325538877e71a4a951cbaeedbbe166798db51803f89101ff240c530858668107a50a026cbcad7b3d90ec2e446a7dacb32ef958c10ace517df914eb23
7
- data.tar.gz: eeea90ecc952afebd4cf8f4b3e8a9c5fdd0d16680a2a0965164ada3936ed8d8e8c12731c919ee1786ae597200a73b5f963aebbbf7151a1c298e42f9b30b0264a
6
+ metadata.gz: c931546fc9101a0b606c6d1e0f827665bb96336b3ca3601797eea6ff2e2b370c67255fa2a6c9dc1642ea932f6da702253602c86067784065712e4036ea559b96
7
+ data.tar.gz: af63f4e37f5f24eeadd469dfea03a6d8b38be3180b8f88d122a9f26c77904a6d24765a56dd2bb41a5c28d4ee244a68dd87268f606e56dea193388eaba526dc75
data/lib/collection.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  class Collection
3
- def initialize
4
- end
3
+ def initialize
4
+ end
5
5
  end
@@ -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
- def initialize
8
- @currentId = 0;
9
- @collections = Hash.new
10
- end
8
+ def initialize
9
+ @current_id = 0;
10
+ @collections = Hash.new
11
+ end
11
12
 
12
- ##
13
- # Adds a new collection to the Hash object
14
- #
15
- # Example:
16
- # >> cm = CollectionManager.new
17
- # >> cm.add(Stack.new)
18
- #
19
- # Arguments:
20
- # a collection object, eg. Stack or Queue
21
- #
22
- def add(collection)
23
- @currentId = @currentId + 1
24
- @collections[@currentId] = collection
25
- end
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
- # Deletes a collection from the Hash object
29
- #
30
- # Example:
31
- # >> cm.delete(1)
32
- #
33
- # Arguments:
34
- # id of the collection
35
- #
36
- def delete(id)
37
- @collections.delete(id)
38
- end
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
- # Returns a collection form the Hash id with key as id
42
- #
43
- # Example:
44
- # >> cm.find(1)
45
- # => value at key 1 in the Hash object
46
- # Arguments:
47
- # id of the collection
48
- #
49
- def find(id)
50
- @collections[id]
51
- end
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
- # Returns all the collections
55
- def all
56
- @collections
57
- end
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
- def initialize
5
- super()
6
- @list = Array.new
7
- end
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 push functionality of a stack
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.1
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-19 00:00:00.000000000 Z
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/queue.rb
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