simplexls 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.markdown +17 -0
  2. data/lib/simplexls.rb +26 -0
  3. metadata +48 -0
data/README.markdown ADDED
@@ -0,0 +1,17 @@
1
+ # Simple XLS
2
+
3
+
4
+ This gem builds HTML tables which makes easy import data into Excel, OpenOffice and others applications of this nature. The HTML can also be used to respond to web requests as well.
5
+
6
+ ## Example
7
+
8
+
9
+ xls = SimpleXLS.new ['header1','header2','header3']
10
+
11
+ xls.push [1,2,3]
12
+ xls.push [4,5]
13
+ xls.push [6,7,8]
14
+
15
+ File.open('output.xls', 'w+') { |f|
16
+ f.puts xls
17
+ }
data/lib/simplexls.rb ADDED
@@ -0,0 +1,26 @@
1
+ class SimpleXLS
2
+ attr_accessor :headers, :rows
3
+
4
+ def initialize(headers)
5
+ raise ArugmentError('Row must be an Array') unless headers.is_a?(Array)
6
+
7
+ @headers = headers.nil? ? [] : headers.dup
8
+ @rows = []
9
+ end
10
+
11
+ def push(row)
12
+ raise ArugmentError('Row must be an Array') unless row.is_a?(Array)
13
+ @rows.push(row.dup)
14
+ end
15
+
16
+ def to_s
17
+ output = "<table><thead><tr>"
18
+ output << @headers.collect { |hr| "<th>#{hr}</th>" }.join << "</tr></thead><tbody>"
19
+ output << @rows.collect { |row|
20
+ # even out the row if needed
21
+ row += Array.new(headers.size - row.size) if row.size != headers.size
22
+ "<tr>#{row.collect { |cell| "<td>#{cell}</td>"}.join}</tr>"
23
+ }.join
24
+ output << "</tbody></table>"
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplexls
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - mikeycgto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-27 00:00:00.000000000 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+ description:
16
+ email: mikeycgto@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.markdown
22
+ - lib/simplexls.rb
23
+ has_rdoc: 'false'
24
+ homepage: http://github.com/mikeycgto/simple-xls
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.5.2
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: Simple XLS
48
+ test_files: []