enum_it_out 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +8 -0
- data/bin/enum_it_out +5 -0
- data/lib/enum_it_out.rb +65 -0
- data/test/test_enum_it_out.rb +31 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ccb2194028fb34c759a31af9c372b1228fb72e1
|
4
|
+
data.tar.gz: 14e5eea27010c58c8a0ed33914710ed67161e8ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d54225a2c27ca76f847215dfb003b5b4b74222f6e58a3c0b6e28f40f8aee4fcf194f037906f5a31567d7bb193568674fc3f42657f903803b68b9e6d36719236c
|
7
|
+
data.tar.gz: d61baf702cd103cd37f4ac84fcaaa34a30b2f49eb6a426265772d6540ab2d1efbef7eb3e87d4fcbf443cea1eb3a93946c6ab34bb7bc0d6272aedb38c35d2c1fb
|
data/Rakefile
ADDED
data/bin/enum_it_out
ADDED
data/lib/enum_it_out.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Enumerable
|
2
|
+
def p_it_out
|
3
|
+
if self.is_a? Hash
|
4
|
+
self.each do |k, v|
|
5
|
+
print "#{k}: "
|
6
|
+
p "#{v}"
|
7
|
+
end
|
8
|
+
else
|
9
|
+
self.each do |x|
|
10
|
+
p x
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def hash_it_out
|
16
|
+
#changes an array to a hash
|
17
|
+
raise ArgumentError.new("Array must have an even number of values") unless self.length % 2 == 0
|
18
|
+
new_hash = {}
|
19
|
+
self.flatten
|
20
|
+
self.each_with_index do |x, i|
|
21
|
+
if i % 2 == 0
|
22
|
+
if x.is_a? String
|
23
|
+
x.delete! ":"
|
24
|
+
x = x.to_sym
|
25
|
+
end
|
26
|
+
new_hash[x] = self[i+1]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
return new_hash
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class String
|
36
|
+
def arr_it
|
37
|
+
#changes string into array of words separated by spaces
|
38
|
+
#removes commas
|
39
|
+
self.delete! ","
|
40
|
+
new_array = self.split
|
41
|
+
return new_array
|
42
|
+
end
|
43
|
+
|
44
|
+
def hash_it_out
|
45
|
+
raise ArgumentError.new("String must have an even number of values") unless self.split.length % 2 == 0
|
46
|
+
new_hash = {}
|
47
|
+
string = self
|
48
|
+
string.delete! ":"
|
49
|
+
string.delete! ","
|
50
|
+
while string.include? (" ")
|
51
|
+
key = string.slice!(/\w*\s/)
|
52
|
+
|
53
|
+
if string.include? (" ")
|
54
|
+
value = string.slice!(/\w*\s/)
|
55
|
+
else
|
56
|
+
value = string.slice!(/\w*/)
|
57
|
+
end
|
58
|
+
value.delete!(" ")
|
59
|
+
key = key.delete!(" ").to_sym
|
60
|
+
new_hash[key] = value
|
61
|
+
end
|
62
|
+
return new_hash
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# ### driver code ###
|
2
|
+
# test = [3,4,5,6]
|
3
|
+
# test_string = "name: Stephanie, age: 25"
|
4
|
+
# test_string_2 = "3 4 5 6 8"
|
5
|
+
# test.p_it_out
|
6
|
+
# p test.hash_it_out
|
7
|
+
# p test_string.arr_it
|
8
|
+
# p test_string.arr_it.hash_it_out
|
9
|
+
# p test_string.hash_it_out
|
10
|
+
# # p test_string_2.hash_it_out
|
11
|
+
|
12
|
+
|
13
|
+
# require 'test/unit'
|
14
|
+
require 'minitest/autorun'
|
15
|
+
require '../lib/enum_it_out'
|
16
|
+
|
17
|
+
class Enum_It_Out_Test < Minitest::Test
|
18
|
+
def test_arr_it
|
19
|
+
assert ["name:", "JimBob"], "name: JimBob".arr_it
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_hash_it_out_with_string
|
23
|
+
expected = {:name => "JimBob"}
|
24
|
+
assert expected, "name: JimBob".hash_it_out
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_hash_it_out_with_array
|
28
|
+
expected = {:name => "JimBob"}
|
29
|
+
assert expected, ["name", "JimBob"].hash_it_out
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enum_it_out
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephanie Hutson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: add functions to strings and enumerators to easy view and datatype change
|
14
|
+
email: stephanie.m.hutson@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- Rakefile
|
20
|
+
- lib/enum_it_out.rb
|
21
|
+
- bin/enum_it_out
|
22
|
+
- test/test_enum_it_out.rb
|
23
|
+
homepage: http://rubygems.org/gems/enum_it_out
|
24
|
+
licenses: []
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.0.14
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: This gem does an easy transfer from an array or a string to an array. It
|
46
|
+
also allows a clean display of arrays and hashes
|
47
|
+
test_files:
|
48
|
+
- test/test_enum_it_out.rb
|