collection_manager 0.0.1
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 +7 -0
- data/lib/collection.rb +5 -0
- data/lib/collection_manager.rb +58 -0
- data/lib/list.rb +8 -0
- data/lib/queue.rb +28 -0
- data/lib/stack.rb +47 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 689897b22b48c70e95a880d4da99153abd5d7603
|
4
|
+
data.tar.gz: 30df932ef5b124714821fef674c2f78079851f4b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95ad51fa325538877e71a4a951cbaeedbbe166798db51803f89101ff240c530858668107a50a026cbcad7b3d90ec2e446a7dacb32ef958c10ace517df914eb23
|
7
|
+
data.tar.gz: eeea90ecc952afebd4cf8f4b3e8a9c5fdd0d16680a2a0965164ada3936ed8d8e8c12731c919ee1786ae597200a73b5f963aebbbf7151a1c298e42f9b30b0264a
|
data/lib/collection.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative 'collection'
|
2
|
+
require_relative 'stack'
|
3
|
+
##
|
4
|
+
# Collection Manager Class to manage collections
|
5
|
+
|
6
|
+
class CollectionManager
|
7
|
+
def initialize
|
8
|
+
@currentId = 0;
|
9
|
+
@collections = Hash.new
|
10
|
+
end
|
11
|
+
|
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
|
26
|
+
|
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
|
39
|
+
|
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
|
52
|
+
|
53
|
+
##
|
54
|
+
# Returns all the collections
|
55
|
+
def all
|
56
|
+
@collections
|
57
|
+
end
|
58
|
+
end
|
data/lib/list.rb
ADDED
data/lib/queue.rb
ADDED
@@ -0,0 +1,28 @@
|
|
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
|
data/lib/stack.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative 'list'
|
2
|
+
|
3
|
+
##
|
4
|
+
# Stack class implementing a typical stack data structure
|
5
|
+
|
6
|
+
class Stack < List
|
7
|
+
def initialize(size = nil)
|
8
|
+
super()
|
9
|
+
@size = size
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
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
|
30
|
+
#
|
31
|
+
# Example:
|
32
|
+
# >> s = Stack.new
|
33
|
+
# >> s.push("something")
|
34
|
+
# >> s.pop()
|
35
|
+
# => "something"
|
36
|
+
def pop()
|
37
|
+
if(@list.length == 0)
|
38
|
+
puts "Stack empty!"
|
39
|
+
else
|
40
|
+
@list.pop
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
@list
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: collection_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shirish Parsekar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: collection Manager for managing a collection of objects
|
14
|
+
email: shirish.parsekar@weboniselab.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/collection.rb
|
20
|
+
- lib/collection_manager.rb
|
21
|
+
- lib/list.rb
|
22
|
+
- lib/queue.rb
|
23
|
+
- lib/stack.rb
|
24
|
+
homepage: http://rubygems.org/gems/collection_manager
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.6.6
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: collection Manager for managing a collection of objects
|
48
|
+
test_files: []
|