collection-holder 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-holder.rb +37 -0
- data/lib/que.rb +63 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: ced76622d8af063f82b9e2b47547494795886a66
|
|
4
|
+
data.tar.gz: 0b570165dd9c20208ed33b6356a0808471cc6036
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 339a80db870ee532967cd7d8ccea846ccf846a929a9939868bc6b23f99cfb6281488aa2807df7f8cdb0f803b9832bccedc6cd63afa4634baed454a715e17b6ae
|
|
7
|
+
data.tar.gz: 99d817bf752be0f49a129c219625fbcd719f8a7adf2be535bd4a495fdaf8ea1e3e7f34c5059a56d537d2c00b145d7bc547e7c54c4c0adcd70b3e41ef955f639f
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require_relative "que.rb"
|
|
2
|
+
|
|
3
|
+
class CollectionHolder
|
|
4
|
+
|
|
5
|
+
attr_reader :holder
|
|
6
|
+
|
|
7
|
+
@@collectionID = 0
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@holder = Hash.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def add(collection)
|
|
14
|
+
@holder[key(@@collectionID)] = collection
|
|
15
|
+
@@collectionID += 1
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def find(id)
|
|
19
|
+
@holder[key(id)]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def display
|
|
23
|
+
@holder.each do |key, collection|
|
|
24
|
+
puts "CollectionID##{key.to_s} | #{collection.type} | #{collection.display}\n"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def delete(id)
|
|
29
|
+
@holder.delete(key(id))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
def key(id)
|
|
34
|
+
id.to_s.to_sym
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
data/lib/que.rb
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
$DEFAULT_QUE_SIZE = 10
|
|
2
|
+
|
|
3
|
+
class Que
|
|
4
|
+
|
|
5
|
+
attr_reader :type, :max_size
|
|
6
|
+
|
|
7
|
+
def initialize(data={})
|
|
8
|
+
@type = "Que"
|
|
9
|
+
@max_size = data[:size] || $DEFAULT_QUE_SIZE
|
|
10
|
+
@list = Queue.new
|
|
11
|
+
push_list(data[:list]) if data[:list]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def pop
|
|
15
|
+
if @list.size<1
|
|
16
|
+
puts "Empty collection! Can't pop()"
|
|
17
|
+
elsif
|
|
18
|
+
@list.pop
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def push(item)
|
|
23
|
+
begin
|
|
24
|
+
if @list.size>=@max_size
|
|
25
|
+
puts "Full collection! Can't push(#{item.to_s})"
|
|
26
|
+
elsif
|
|
27
|
+
@list.push(item)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
rescue
|
|
31
|
+
puts "Unable to push #{item.to_s}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def clear
|
|
36
|
+
@list.clear
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def length
|
|
40
|
+
@list.length
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def size
|
|
44
|
+
length
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def empty?
|
|
48
|
+
length==0
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def push_list(list)
|
|
52
|
+
begin
|
|
53
|
+
list.each { |data| @list.push data } if list.is_a? Array
|
|
54
|
+
rescue
|
|
55
|
+
puts "Unable to push list #{list.to_s}"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def display
|
|
60
|
+
@list.to_s
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: collection-holder
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
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-holder.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: []
|