sarray 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Rakefile +8 -0
- data/bin/sarray +4 -0
- data/lib/sarray.rb +63 -0
- data/lib/sarray/translator.rb +16 -0
- data/test/test_sarray.rb +16 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDg1OGMyNDk0NjZmZDYzOGE5ZDI2MjEwZDcxNjgwN2U5NDJlMGM3Zg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YmRmNjE2NTViNDcyMDRlMzY2MjliNzZjMTYyODYyNDk0NjZlMGUwOA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OWQ1ODRhNzMxZGEzOTAzZjQyYjg0MWMwNTM4MGMxMTE3MjVkNzk2OWQ4ZjRj
|
10
|
+
NGNmODExMDk2ZjM2NzEwYTgzMWU3Njc4M2E4Nzc1NGMyNjdkMzFlMWI1MDg2
|
11
|
+
NzhkODI0YTJhY2E1MTZmYTQ1NzdkNzNiYTc0NjIzZmM0MmQzZTQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YmYxMGFjZWVmMTVmNTI1MGEyNDI1MGYwZTA3YTY2ODJiZWE5NGQzNWNjODVk
|
14
|
+
NGNiNTU4ZTEyN2Q1YTA0Y2ZlMjYxZDhiN2VmMTUzNmM1ZDQ0MTYxZWNhYWZk
|
15
|
+
OWNhNmVhNzNlYmQ1ZjVhMDI3MzMwYzUxZWIyMTUwOTgwZDVkYzA=
|
data/Rakefile
ADDED
data/bin/sarray
ADDED
data/lib/sarray.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
class Sarray
|
2
|
+
def self.string_arr_to_arr(str)
|
3
|
+
str << " "
|
4
|
+
|
5
|
+
#Output file length
|
6
|
+
puts str.length
|
7
|
+
|
8
|
+
#create a temporary array
|
9
|
+
arr = []
|
10
|
+
main_hash = []
|
11
|
+
temp_hash = {}
|
12
|
+
field_1 = ""
|
13
|
+
field = ""
|
14
|
+
i = -1
|
15
|
+
while i < str.length-2
|
16
|
+
i = i + 1
|
17
|
+
|
18
|
+
if ["[","{"].include?(str[i])
|
19
|
+
temp_hash = {}
|
20
|
+
field = ""
|
21
|
+
next
|
22
|
+
end
|
23
|
+
|
24
|
+
#if it is an arrow head skip to the next character
|
25
|
+
if [">","\""].include?(str[i])
|
26
|
+
next
|
27
|
+
end
|
28
|
+
|
29
|
+
#Check for new brackets and exclude from the data
|
30
|
+
if not ["[","{","}","]"].include?(str[i])
|
31
|
+
|
32
|
+
#if the current string is =>
|
33
|
+
if "#{str[i]}" == "="
|
34
|
+
field_1 = field
|
35
|
+
field = ""
|
36
|
+
next
|
37
|
+
end
|
38
|
+
|
39
|
+
# if the current value is a comma ( , ) then u create the hash value
|
40
|
+
if "#{str[i]}#{str[i+1]}#{str[i+2]}" == ", \""
|
41
|
+
temp_hash[field_1] = field
|
42
|
+
field = ""
|
43
|
+
i = i + 2
|
44
|
+
next
|
45
|
+
end
|
46
|
+
|
47
|
+
field << str[i]
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
if str[i] == "}"
|
52
|
+
main_hash << temp_hash
|
53
|
+
next
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
puts "\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>"
|
58
|
+
puts "Array generation complete\n"
|
59
|
+
puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n"
|
60
|
+
|
61
|
+
return main_hash
|
62
|
+
end
|
63
|
+
end
|
data/test/test_sarray.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'sarray'
|
3
|
+
|
4
|
+
class SarryTest < Test::Unit::TestCase
|
5
|
+
def test_english_hello
|
6
|
+
assert_equal "hello world", Hola.hi("english")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_any_hello
|
10
|
+
assert_equal "hello world", Hola.hi("ruby")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_spanish_hello
|
14
|
+
assert_equal "hola mundo", Hola.hi("spanish")
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sarray
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrews Peprah
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem which converts a String array of hashes into an array of hashes
|
14
|
+
email: andrewspeprah@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- Rakefile
|
20
|
+
- bin/sarray
|
21
|
+
- lib/sarray.rb
|
22
|
+
- lib/sarray/translator.rb
|
23
|
+
- test/test_sarray.rb
|
24
|
+
homepage: http://rubygems.org/gems/sarray
|
25
|
+
licenses: []
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.4.5
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: Sarray!
|
47
|
+
test_files:
|
48
|
+
- test/test_sarray.rb
|