collection-manager 0.0.0
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-manager.rb +35 -0
- data/lib/que.rb +69 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ff59ba0dfb29fe330a88a839c3dfc307e75520e6
|
4
|
+
data.tar.gz: 8b88668d146ff4cc1f855361d9aed596616a98e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05e4f29946e5c65f4631e61cd63b7a6df6a077b8d184363561a2430468d58ec74949758d41c4210ea8874d843eeef8cf5ef43e51489d4f6f62da8d470a9f0ae5
|
7
|
+
data.tar.gz: ee99af72d296aa0f79c75d356bbf339f8f574a7b1e8584e30f888b48296e89f2e035587a3802ecd498fb98c97ed645d155b5ca1b4ad2a01602b115eeecb21d0e
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative "que.rb"
|
2
|
+
require 'byebug'
|
3
|
+
|
4
|
+
class CollectionManager
|
5
|
+
|
6
|
+
attr_reader :list
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@list = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def add(collection)
|
13
|
+
@list.push collection
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(id)
|
17
|
+
output = @list.select do |q|
|
18
|
+
q.id == id
|
19
|
+
end
|
20
|
+
output[0]
|
21
|
+
end
|
22
|
+
|
23
|
+
def display_all
|
24
|
+
@list.each do |q|
|
25
|
+
puts "CollectionID##{q.id} | #{q.type} | #{q.display}\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete(id)
|
30
|
+
@list.reject! do |q|
|
31
|
+
q.id == id
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/que.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'byebug'
|
2
|
+
|
3
|
+
$DEFAULT_QUE_SIZE = 10
|
4
|
+
|
5
|
+
class Que
|
6
|
+
|
7
|
+
@@QueueID = 0
|
8
|
+
|
9
|
+
attr_reader :id, :type, :max_size
|
10
|
+
|
11
|
+
def initialize(data={})
|
12
|
+
@type = "Que"
|
13
|
+
@id = @@QueueID
|
14
|
+
@list = Queue.new
|
15
|
+
@@QueueID += 1
|
16
|
+
@max_size = $DEFAULT_QUE_SIZE
|
17
|
+
@max_size = data[:size] if data[:size]
|
18
|
+
push_list(data[:list]) if data[:list]
|
19
|
+
end
|
20
|
+
|
21
|
+
def pop
|
22
|
+
if @list.size<1
|
23
|
+
puts "Empty collection! Can't pop()"
|
24
|
+
elsif
|
25
|
+
@list.pop
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def push(x)
|
30
|
+
begin
|
31
|
+
if @list.size>=max_size
|
32
|
+
puts "Full collection! Can't push(#{x.to_s})"
|
33
|
+
elsif
|
34
|
+
@list.push(x)
|
35
|
+
end
|
36
|
+
rescue
|
37
|
+
puts "Unable to push #{x.to_s}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def clear
|
42
|
+
@list.clear
|
43
|
+
end
|
44
|
+
|
45
|
+
def length
|
46
|
+
@list.length
|
47
|
+
end
|
48
|
+
|
49
|
+
def size
|
50
|
+
length
|
51
|
+
end
|
52
|
+
|
53
|
+
def empty?
|
54
|
+
length==0
|
55
|
+
end
|
56
|
+
|
57
|
+
def push_list(list)
|
58
|
+
begin
|
59
|
+
list.each { |data| @list.push data } if list.is_a? Array
|
60
|
+
rescue
|
61
|
+
puts "Unable to push list #{list.to_s}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def display
|
66
|
+
@list.to_s
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: collection-manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Raj Negi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple gem to manage your queues or any data structure!
|
14
|
+
email: raj.negi@weboniselab.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/collection-manager.rb
|
20
|
+
- lib/que.rb
|
21
|
+
homepage: https://github.com/rajn-webonise/RubyAssignments
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.5.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Manages your data structures
|
45
|
+
test_files: []
|