Class: Sarray

Inherits:
Object
  • Object
show all
Defined in:
lib/sarray.rb

Class Method Summary collapse

Class Method Details

.string_arr_to_arr(str) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sarray.rb', line 2

def self.string_arr_to_arr(str)
	str << "  "

	#Output file length
	puts str.length

	#create a temporary array
	arr = []
	main_hash = []
	temp_hash = {}
	field_1 = ""
	field = ""
	i = -1 
	while i < str.length-2
i = i + 1

if ["[","{"].include?(str[i])
	temp_hash = {}
	field = ""
	next
end

#if it is an arrow head skip to the next character
if [">","\""].include?(str[i])
	next
end

#Check for new brackets and exclude from the data
if not ["[","{","}","]"].include?(str[i])

	#if the current string is =>
	if "#{str[i]}" == "="
		field_1 = field
		field = ""				
		next
	end

	# if the current value is a comma ( , ) then u create the hash value
	if "#{str[i]}#{str[i+1]}#{str[i+2]}" == ", \""
		temp_hash[field_1] = field
		field = ""
		i = i + 2
		next
	end

	field << str[i]
end


if str[i] == "}"
	main_hash << temp_hash
	next
end		
	end
	
	puts "\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>"
	puts "Array generation complete\n"
	puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n"

	return main_hash
end