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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf2febec784c194d3e592c78776f535a15458009
4
- data.tar.gz: 9e9a0c83fe42ba73acc0d0b579197194a0ee786b
3
+ metadata.gz: 48e91b5c946f7d5a9b1fb0ed62452f1055de78ec
4
+ data.tar.gz: 1495c00e8514be860b54d1e02ff4ffa9f82fa411
5
5
  SHA512:
6
- metadata.gz: b141c54fa32c28b2d320885323c7ebf77f941758d07996e5fe435354c1f1d8c1cc3928ebc22f27c2051e31f46a28f6bc86a576696651704a39f6206b429f79c9
7
- data.tar.gz: 7eaac74f6bb96cb5c00537b018d80b925f72704545be91e0d83c7e03e9e3cf8c6996cfa1efd8174871d26fe7fa311b293c4bbcb83feb38e6235f327a3b028cbd
6
+ metadata.gz: acb897ffbe48632d04fa246362ab284eb5bde0cb1bdeda11e8b8bb492e4500401695c1dadea82cf57e749087a8988a3f28963261a008a4fa3936f3689cd05eb5
7
+ data.tar.gz: 235f5dcf5325942c4d5fafd3e1e0eba396193c4a3bce23c22383b1588c2742cc9be22a94480c1d03a689311124ada0431d208db8ede166727f394e31357cdf8a
data/src/excel_to_code.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class ExcelToCode
2
- def self.version() "0.3.1" end
2
+ def self.version() "0.3.2" end
3
3
  end
4
4
 
5
5
  require_relative 'commands'
@@ -1,6 +1,6 @@
1
- require 'nokogiri'
1
+ require 'ox'
2
2
 
3
- class ExtractRelationships < Nokogiri::XML::SAX::Document
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(input)
11
+ def extract(input_xml)
12
12
  @input, @output = input, {}
13
- parser = Nokogiri::XML::SAX::Parser.new(self)
14
- parser.parse(input)
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,attributes)
19
- return false unless name == "Relationship"
20
- @output[attributes.assoc('Id').last] = attributes.assoc('Target').last
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 'nokogiri'
1
+ require 'ox'
2
2
 
3
- class ExtractSharedStrings < Nokogiri::XML::SAX::Document
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(input)
10
- @input, @output = input, []
9
+ def extract(input_xml)
10
+ @output = []
11
11
  @current = nil
12
- parser = Nokogiri::XML::SAX::Parser.new(self)
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,attributes)
18
- @current = [] if name == "si"
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 == "si"
21
+ return unless name == :si
23
22
  @output << [:string, @current.join]
24
23
  @current = nil
25
24
  end
26
25
 
27
- def characters(string)
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 'nokogiri'
1
+ require 'ox'
2
2
 
3
- class ExtractTable < Nokogiri::XML::SAX::Document
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, input)
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
- @parsing = false
18
- Nokogiri::XML::SAX::Parser.new(self).parse(input)
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,attributes)
23
- if name == "table"
24
- @table_name = attributes.assoc('displayName').last
25
- @table_ref = attributes.assoc('ref').last
26
- @table_total_rows = attributes.assoc('totalsRowCount').try(:last) || "0"
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
- elsif name == "tableColumn"
29
- @table_columns << attributes.assoc('name').last
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
- return unless name == "table"
35
- @output[@table_name] = [@sheet_name, @table_ref, @table_total_rows, *@table_columns]
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 'nokogiri'
1
+ require 'ox'
2
2
 
3
- class ExtractWorksheetNames < Nokogiri::XML::SAX::Document
3
+ class ExtractWorksheetNames < ::Ox::Sax
4
4
 
5
- attr_accessor :input, :output
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(input)
12
- @input, @output = input, {}
13
- parser = Nokogiri::XML::SAX::Parser.new(self)
14
- parser.parse(input)
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,attributes)
19
- return false unless name == "sheet"
20
- output[attributes.assoc('name').last] = attributes.assoc('r:id').last
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.1
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-25 00:00:00.000000000 Z
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