rolesCounter 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/rolesCounter.rb +28 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7166cefa5ec17ba60cb424f401081cc84a8bbef7648a259beb5122d70ab3ccb8
|
|
4
|
+
data.tar.gz: 47707c9e21c82bfaf57db71f9232aa499c1805c7333215a6a9d62cf4a5d99a68
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 416e61a23a756a6eaeb4a2908027bdc7e0c3b72d597d6193ceba4fef721f9a972ad2734ba2010c0a3591af001d32423273f7636ccd34207f5434d3e58ad3d1f2
|
|
7
|
+
data.tar.gz: fe756ad39fafcd74b4cdff2eb2e6c5d78e9592693f1879f274356817b8afeea81626ebb2f46d7eeb76eeeb0310d607996b2e735f1e7a15c1d5c602cf82755081
|
data/lib/rolesCounter.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class RolesCounter
|
|
2
|
+
# Static method that receives the string with all the roles in the
|
|
3
|
+
# database stored in a hash separated by commas. The string is split and
|
|
4
|
+
# is returned in a hash indicating the role and its ocurrences.
|
|
5
|
+
def self.counter(roles_string)
|
|
6
|
+
@roles_string = roles_string
|
|
7
|
+
# Checks if the string is valid calling the method
|
|
8
|
+
# stringCheck, if it is will return the hash
|
|
9
|
+
# with the roles and the corresponding count.
|
|
10
|
+
if stringCheck(@roles_string) then
|
|
11
|
+
@roles_array = Array.new
|
|
12
|
+
@roles_array = @roles_string.split(", ")
|
|
13
|
+
return @roles_array.group_by(&:to_s).map {
|
|
14
|
+
|a| [a[0], a[1].count]
|
|
15
|
+
}.to_h
|
|
16
|
+
else
|
|
17
|
+
return "Invalid group of roles."
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Method that checks if the given string is a valid string
|
|
22
|
+
# separated by commas and a space after the comma.
|
|
23
|
+
def self.stringCheck(string_check)
|
|
24
|
+
@string_check = string_check
|
|
25
|
+
return @string_check =~ /\A[a-zA-Z\s]+(,[\sa-zA-Z]+)*\z/
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rolesCounter
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dorya Rascon
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-04-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: |-
|
|
14
|
+
Verifies that the string of roles is valid and
|
|
15
|
+
counts the ocurrences of each role.
|
|
16
|
+
email: dsrascon@gmail.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- lib/rolesCounter.rb
|
|
22
|
+
homepage: http://rubygems.org/gems/rolesCounter
|
|
23
|
+
licenses: []
|
|
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
|
+
rubygems_version: 3.1.2
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: Returns the count of each existing role
|
|
44
|
+
test_files: []
|