tables 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ #
2
+ # Author:: Saul Caganoff (mailto:scaganoff@gmail.com)
3
+ # Copyright:: Copyright (c) 2010, Saul Caganoff
4
+ # License:: Creative Commons Attribution 3.0 Australia License (http://creativecommons.org/licenses/by/3.0/au/)
5
+ #
6
+
7
+ require 'tables'
8
+
9
+ describe Tables::ExcelTableReader do
10
+
11
+ it "should extract a table" do
12
+ filename=File.dirname(__FILE__)+"/../test/rtm2.xlsx"
13
+ @xtr = Tables::ExcelTableReader.new(filename)
14
+ t=@xtr.extract_table("Requirements",{:rtf_columns=>[2], :progress=>true})
15
+
16
+ t[7][2].should=="The message content should have the following fields.
17
+ - Message Id (Mandatory)
18
+ - Message Priority (Mandatory)
19
+ - Message Delivery Method (e.g. Portal, IHD ) (Mandatory)
20
+ - Message Type (e.g. Alert , General) (Mandatory)
21
+ - Message Text (Mandatory)
22
+ - Link(s) (embedded in text) (Optional)
23
+ - Message Start Timestamp (Mandatory)
24
+ - Message End timestamp (Mandatory)
25
+ - Recipient ID list (e.g. NMI) ( Mandatory)
26
+ - Group ID (Optional)
27
+ - Message Action (Mandatory)
28
+ - Sender (i.e. who is instigating the message)"
29
+
30
+ t[5][2].should==""
31
+ t[5][0].should=="CACP.OA.04"
32
+
33
+ @xtr.exit
34
+ end
35
+
36
+ end
37
+
@@ -0,0 +1,70 @@
1
+ #
2
+ # Author:: Saul Caganoff (mailto:scaganoff@gmail.com)
3
+ # Copyright:: Copyright (c) 2010, Saul Caganoff
4
+ # License:: Creative Commons Attribution 3.0 Australia License (http://creativecommons.org/licenses/by/3.0/au/)
5
+ #
6
+
7
+ require 'tables'
8
+
9
+ describe Tables::WordTableReader do
10
+
11
+ it "should read a word document" do
12
+ filename=File.dirname(__FILE__)+"/../test/rtm.docx"
13
+ @wtr = Tables::WordTableReader.new(filename)
14
+ @wtr.doc.should_not==nil
15
+ @wtr.exit
16
+ end
17
+
18
+ it "should count the tables" do
19
+ filename=File.dirname(__FILE__)+"/../test/rtm.docx"
20
+ @wtr = Tables::WordTableReader.new(filename)
21
+ @wtr.doc.should_not==nil
22
+ @wtr.doc.tables.count.should==55
23
+ @wtr.exit
24
+ end
25
+
26
+ it "should extract a table" do
27
+ filename=File.dirname(__FILE__)+"/../test/rtm.docx"
28
+ @wtr = Tables::WordTableReader.new(filename)
29
+ t=@wtr.extract_table(21)
30
+ t.rows.should==13
31
+ t[0][0].should=~/Unique ID/
32
+ t[1][0].should=~/CAMM\.SC\.101/
33
+ end
34
+
35
+ it "should extract all tables" do
36
+ filename=File.dirname(__FILE__)+"/../test/rtm.docx"
37
+ @wtr = Tables::WordTableReader.new(filename)
38
+ @wtr.extract_all_tables((0..53).to_a) # TODO: Problem extracting last table should be 0..55
39
+ @wtr.tables.count.should==54
40
+ end
41
+
42
+ it "should filter tables on extract" do
43
+ filename=File.dirname(__FILE__)+"/../test/rtm.docx"
44
+ @wtr = Tables::WordTableReader.new(filename)
45
+ @wtr.extract_all_tables((0..53).to_a) {|table| table[0][0]=~/Unique ID/} # TODO: Problem extracting last table should be 0..55
46
+ @wtr.tables.count.should==35
47
+ end
48
+
49
+ it "should merge similar tables" do
50
+ filename=File.dirname(__FILE__)+"/../test/rtm.docx"
51
+ @wtr = Tables::WordTableReader.new(filename)
52
+ @wtr.extract_all_tables((0..53).to_a) # TODO: Problem extracting last table should be 0..55
53
+ @wtr.merge_tables
54
+ @wtr.tables.count.should==19
55
+ end
56
+
57
+ it "should return tables matching a filter" do
58
+ filename=File.dirname(__FILE__)+"/../test/rtm.docx"
59
+ @wtr = Tables::WordTableReader.new(filename)
60
+ @wtr.extract_all_tables((0..53).to_a) # TODO: Problem extracting last table should be 0..55
61
+ @wtr.merge_tables
62
+ tables=@wtr.get_tables {|table| table[0][0]=~/Unique ID/}
63
+ tables.count.should==1
64
+ column1=[]
65
+ tables[0].each_row {|row| column1<< row[0] }
66
+ column1.count.should==382
67
+ end
68
+
69
+ end
70
+
@@ -0,0 +1,37 @@
1
+ #
2
+ # Author:: Saul Caganoff (mailto:scaganoff@gmail.com)
3
+ # Copyright:: Copyright (c) 2010, Saul Caganoff
4
+ # License:: Creative Commons Attribution 3.0 Australia License (http://creativecommons.org/licenses/by/3.0/au/)
5
+ #
6
+ require "rspec"
7
+ require 'tables'
8
+
9
+ describe Tables::WordTableWriter do
10
+
11
+ before(:each) do
12
+ @wtw=Tables::WordTableWriter.new
13
+ @table=Tables::Table.new([
14
+ ["Header 1", "Header 2", "Header 3"],
15
+ ["Cell(2,1)","Cell(2,2)","Cell(2,3)"],
16
+ ["Cell(3,1)","Cell(3,2)","Cell(3,3)"],
17
+ ["Cell(4,1)","Cell(4,2)","Cell(4,3)"],
18
+ ["Cell(5,1)","Cell(5,2)","Cell(5,3)"],
19
+ ["Cell(6,1)","Cell(6,2)","Cell(6,3)"]
20
+ ])
21
+ @outfile=File.dirname(__FILE__)+"/../test/table_writer_test.docx"
22
+ begin; File.delete(@outfile); rescue; end
23
+ end
24
+
25
+ it "should write a table to word" do
26
+ File.exists?(@outfile).should==false
27
+ @wtw.append_table(@table, "This is my very nice table.")
28
+ @wtw.save_as(@outfile)
29
+ @wtw.exit
30
+ File.exists?(@outfile).should==true
31
+
32
+ @wtr=Tables::WordTableReader.new(@outfile)
33
+ t_result=@wtr.extract_table(0)
34
+ t_result.should.eql? @table
35
+ end
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tables
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.14
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Saul Caganoff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-07 00:00:00.000000000 +10:00
13
+ default_executable:
14
+ dependencies: []
15
+ description: Manage two-dimensional text tables including read/write to Word and Excel.
16
+ email: scaganoff@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README
21
+ - LICENSE
22
+ files:
23
+ - LICENSE
24
+ - README
25
+ - Rakefile
26
+ - lib/tables/excel_table_reader.rb
27
+ - lib/tables/table.rb
28
+ - lib/tables/table_reader.rb
29
+ - lib/tables/word_table_reader.rb
30
+ - lib/tables/word_table_writer.rb
31
+ - lib/tables.rb
32
+ - spec/copy_spec.rb
33
+ - spec/excel_table_reader_spec.rb
34
+ - spec/office_copy_spec.rb
35
+ - spec/table_spec.rb
36
+ - spec/text_handling_spec.rb
37
+ - spec/word_table_reader_spec.rb
38
+ - spec/word_table_writer_spec.rb
39
+ has_rdoc: true
40
+ homepage:
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.5.2
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Manage two-dimensional text tables including read/write to Word and Excel.
64
+ test_files: []