excel_to_code 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/src/excel_to_code.rb +1 -1
- data/src/extract/extract_relationships.rb +26 -8
- data/src/extract/extract_shared_strings.rb +9 -10
- data/src/extract/extract_table.rb +45 -14
- data/src/extract/extract_worksheet_names.rb +27 -11
- metadata +2 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48e91b5c946f7d5a9b1fb0ed62452f1055de78ec
|
4
|
+
data.tar.gz: 1495c00e8514be860b54d1e02ff4ffa9f82fa411
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acb897ffbe48632d04fa246362ab284eb5bde0cb1bdeda11e8b8bb492e4500401695c1dadea82cf57e749087a8988a3f28963261a008a4fa3936f3689cd05eb5
|
7
|
+
data.tar.gz: 235f5dcf5325942c4d5fafd3e1e0eba396193c4a3bce23c22383b1588c2742cc9be22a94480c1d03a689311124ada0431d208db8ede166727f394e31357cdf8a
|
data/src/excel_to_code.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'ox'
|
2
2
|
|
3
|
-
class ExtractRelationships <
|
3
|
+
class ExtractRelationships < ::Ox::Sax
|
4
4
|
|
5
5
|
attr_accessor :input, :output
|
6
6
|
|
@@ -8,16 +8,34 @@ class ExtractRelationships < Nokogiri::XML::SAX::Document
|
|
8
8
|
self.new.extract(*args)
|
9
9
|
end
|
10
10
|
|
11
|
-
def extract(
|
11
|
+
def extract(input_xml)
|
12
12
|
@input, @output = input, {}
|
13
|
-
|
14
|
-
|
13
|
+
@state = :not_in_relationship
|
14
|
+
Ox.sax_parse(self, input_xml, :convert_special => true)
|
15
15
|
output
|
16
16
|
end
|
17
17
|
|
18
|
-
def start_element(name
|
19
|
-
return false unless name ==
|
20
|
-
@
|
18
|
+
def start_element(name)
|
19
|
+
return false unless name == :Relationship
|
20
|
+
@state = :in_relationship
|
21
|
+
end
|
22
|
+
|
23
|
+
def attr(name, value)
|
24
|
+
return unless @state == :in_relationship
|
25
|
+
case name
|
26
|
+
when :Id
|
27
|
+
@id = value
|
28
|
+
when :Target
|
29
|
+
@target = value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def end_element(name)
|
34
|
+
return unless @state == :in_relationship
|
35
|
+
return unless name == :Relationship
|
36
|
+
@output[@id] = @target
|
37
|
+
@state = :not_in_relationship
|
38
|
+
@id, @target = nil, nil
|
21
39
|
end
|
22
40
|
|
23
41
|
end
|
@@ -1,30 +1,29 @@
|
|
1
|
-
require '
|
1
|
+
require 'ox'
|
2
2
|
|
3
|
-
class ExtractSharedStrings <
|
3
|
+
class ExtractSharedStrings < ::Ox::Sax
|
4
4
|
|
5
5
|
def self.extract(input)
|
6
6
|
self.new.extract(input)
|
7
7
|
end
|
8
8
|
|
9
|
-
def extract(
|
10
|
-
@
|
9
|
+
def extract(input_xml)
|
10
|
+
@output = []
|
11
11
|
@current = nil
|
12
|
-
|
13
|
-
parser.parse(input)
|
12
|
+
Ox.sax_parse(self, input_xml, :convert_special => true)
|
14
13
|
@output
|
15
14
|
end
|
16
15
|
|
17
|
-
def start_element(name
|
18
|
-
@current = [] if name ==
|
16
|
+
def start_element(name)
|
17
|
+
@current = [] if name == :si
|
19
18
|
end
|
20
19
|
|
21
20
|
def end_element(name)
|
22
|
-
return unless name ==
|
21
|
+
return unless name == :si
|
23
22
|
@output << [:string, @current.join]
|
24
23
|
@current = nil
|
25
24
|
end
|
26
25
|
|
27
|
-
def
|
26
|
+
def text(string)
|
28
27
|
return unless @current
|
29
28
|
# FIXME: SHOULDN'T ELINMATE NEWLINES
|
30
29
|
@current << string.gsub("\n","")
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'ox'
|
2
2
|
|
3
|
-
class ExtractTable <
|
3
|
+
class ExtractTable < ::Ox::Sax
|
4
4
|
|
5
5
|
def self.extract(*args)
|
6
6
|
self.new.extract(*args)
|
7
7
|
end
|
8
8
|
|
9
|
-
def extract(sheet_name,
|
9
|
+
def extract(sheet_name, input_xml)
|
10
10
|
@sheet_name = sheet_name
|
11
11
|
@output = {}
|
12
12
|
@table_name = nil
|
@@ -14,24 +14,55 @@ class ExtractTable < Nokogiri::XML::SAX::Document
|
|
14
14
|
@table_total_rows = nil
|
15
15
|
@table_columns = nil
|
16
16
|
|
17
|
-
@
|
18
|
-
|
17
|
+
@state = :not_parsing
|
18
|
+
Ox.sax_parse(self, input_xml, :convert_special => true)
|
19
19
|
@output
|
20
20
|
end
|
21
21
|
|
22
|
-
def start_element(name
|
23
|
-
|
24
|
-
|
25
|
-
@
|
26
|
-
@
|
22
|
+
def start_element(name)
|
23
|
+
case name
|
24
|
+
when :table
|
25
|
+
@table_name = nil
|
26
|
+
@table_ref = nil
|
27
|
+
@table_total_rows = nil
|
27
28
|
@table_columns = []
|
28
|
-
|
29
|
-
|
29
|
+
@state = :parsing_table
|
30
|
+
when :tableColumn
|
31
|
+
@state = :parsing_table_column
|
32
|
+
else
|
33
|
+
@state = :not_parsing
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def attr(name, value)
|
38
|
+
case @state
|
39
|
+
when :not_parsing
|
40
|
+
return
|
41
|
+
when :parsing_table_column
|
42
|
+
case name
|
43
|
+
when :name
|
44
|
+
@table_columns << value
|
45
|
+
end
|
46
|
+
when :parsing_table
|
47
|
+
case name
|
48
|
+
when :displayName
|
49
|
+
@table_name = value
|
50
|
+
when :ref
|
51
|
+
@table_ref = value
|
52
|
+
when :totalsRowCount
|
53
|
+
@table_total_rows = value
|
54
|
+
end
|
30
55
|
end
|
31
56
|
end
|
32
57
|
|
33
58
|
def end_element(name)
|
34
|
-
|
35
|
-
|
59
|
+
case name
|
60
|
+
when :tableColumn
|
61
|
+
@state = :parsing_table
|
62
|
+
when :table
|
63
|
+
@output[@table_name] = [@sheet_name, @table_ref, @table_total_rows || "0", *@table_columns]
|
64
|
+
@state = :not_parsing
|
65
|
+
end
|
66
|
+
|
36
67
|
end
|
37
68
|
end
|
@@ -1,23 +1,39 @@
|
|
1
|
-
require '
|
1
|
+
require 'ox'
|
2
2
|
|
3
|
-
class ExtractWorksheetNames <
|
3
|
+
class ExtractWorksheetNames < ::Ox::Sax
|
4
4
|
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :output
|
6
6
|
|
7
7
|
def self.extract(*args)
|
8
8
|
self.new.extract(*args)
|
9
9
|
end
|
10
10
|
|
11
|
-
def extract(
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
output
|
11
|
+
def extract(input_xml)
|
12
|
+
@output = {}
|
13
|
+
@state = :not_parsing
|
14
|
+
Ox.sax_parse(self, input_xml, :convert_special => true)
|
15
|
+
@output
|
16
16
|
end
|
17
17
|
|
18
|
-
def start_element(name
|
19
|
-
return false unless name ==
|
20
|
-
|
18
|
+
def start_element(name)
|
19
|
+
return false unless name == :sheet
|
20
|
+
@state = :parsing
|
21
|
+
end
|
22
|
+
|
23
|
+
def attr(attr_name, value)
|
24
|
+
return unless @state == :parsing
|
25
|
+
case attr_name
|
26
|
+
when :name
|
27
|
+
@name = value
|
28
|
+
when :"r:id"
|
29
|
+
@rid = value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def end_element(name)
|
34
|
+
return false unless name == :sheet
|
35
|
+
output[@name] = @rid
|
36
|
+
@state = :not_parsing
|
21
37
|
end
|
22
38
|
|
23
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: excel_to_code
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Counsell, Green on Black Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubypeg
|
@@ -24,26 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: nokogiri
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.5'
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 1.5.0
|
37
|
-
type: :runtime
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - "~>"
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '1.5'
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.5.0
|
47
27
|
- !ruby/object:Gem::Dependency
|
48
28
|
name: rspec
|
49
29
|
requirement: !ruby/object:Gem::Requirement
|