format_data_converter 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +17 -2
- data/lib/format_data_converter/converter.rb +1 -2
- data/lib/format_data_converter/hasher.rb +17 -14
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -1,2 +1,17 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Format Data Converter
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Because, if you work with many data formats, you need gems specifically for each of the types you're working with, Format Data Converter comes to help you, autodetecting the input type from a number of known types (JSON, XML, CSV, Hash, Activerecord) and converting it to the type required in your application (currently supporting JSON, XML, CSV, Excel and Hash and working on YAML).
|
5
|
+
|
6
|
+
To install, run:
|
7
|
+
|
8
|
+
gem install format_data_converter -v '0.9.0'
|
9
|
+
|
10
|
+
To convert, you need to run:
|
11
|
+
|
12
|
+
FDC.detect_and_to_*FORMAT*, where format may be csv, json, hash_symbols (puts symbols instead of strings), hash, xml, xls.
|
13
|
+
|
14
|
+
As this is a beta version, there are still improvements to be made. Feel free to expand the code and make it better!
|
15
|
+
|
16
|
+
Hope this gem helps you when you work with multiple data types.
|
17
|
+
|
@@ -22,30 +22,33 @@ class Hasher
|
|
22
22
|
|
23
23
|
def self.from_xml s
|
24
24
|
shash = ""
|
25
|
-
arbre = []
|
26
25
|
for i in 0..s.length-2
|
27
|
-
if (s[i] == ">")
|
26
|
+
if (s[i] == ">")
|
28
27
|
if (s[i+1] == "<")
|
29
|
-
if (s[i+2] != "/")
|
28
|
+
if (s[i+2] != "/")
|
29
|
+
saux = s.clone
|
30
|
+
if (s[saux.index(">", i+2)+2 .. saux.index(">", i+2)+3] == "</") then shash << '"=>['
|
31
|
+
else shash<< ","
|
32
|
+
end
|
30
33
|
end
|
31
34
|
else shash << '"=>'
|
32
|
-
|
33
|
-
|
35
|
+
saux = s.clone
|
36
|
+
shash << '"' << saux.slice(i+1..(saux.index("<", i+2)-1)) << '"'
|
34
37
|
end
|
35
|
-
|
36
|
-
|
38
|
+
elsif (s[i] == "<")
|
39
|
+
if (s[i+1] == "/")
|
40
|
+
saux = s.clone
|
41
|
+
if (s[saux.index(">", i+1)+1 .. saux.index(">", i+1)+2] == "</") then shash << '}]'
|
42
|
+
else shash << '}'
|
43
|
+
end
|
44
|
+
else shash << '{"'
|
37
45
|
saux = s.clone
|
38
|
-
|
39
|
-
else shash << '}'
|
40
|
-
end
|
41
|
-
else shash << '{"'
|
42
|
-
saux = s.clone
|
43
|
-
shash << saux.slice(i+1..(saux.index(">", i+2)-1))
|
46
|
+
shash << saux.slice(i+1..(saux.index(">", i+2)-1))
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
47
50
|
shash
|
48
|
-
end
|
51
|
+
end
|
49
52
|
|
50
53
|
def self.from_json s
|
51
54
|
s.gsub(":","=>")
|