xmlss 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xmlss (0.0.1)
4
+ xmlss (0.0.2)
5
+ enumeration (~> 1.1.0)
5
6
  nokogiri (~> 1.4.0)
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
9
10
  specs:
11
+ enumeration (1.1.0)
10
12
  json (1.5.1)
11
13
  kelredd-useful (0.4.1)
12
14
  json
@@ -23,6 +25,7 @@ PLATFORMS
23
25
 
24
26
  DEPENDENCIES
25
27
  bundler (~> 1.0)
28
+ enumeration (~> 1.1.0)
26
29
  nokogiri (~> 1.4.0)
27
30
  test-belt (= 0.2.1)
28
31
  xmlss!
data/README.rdoc CHANGED
@@ -70,14 +70,12 @@ These classes define how a spreadsheet is constructed.
70
70
  === Xmlss::Cell
71
71
  * *style_id*: string
72
72
  * *data*: Xmlss::Data object
73
- * *formula*: string
74
73
  * *href*: string
75
74
  * *merge_across*: int, default: 0
76
75
  * *merge_down*: int, default: 0
77
- * *tool_tip*: string
78
76
 
79
77
  === Xmlss::Data
80
- * *type*: :number, :datetime, :boolean, :string, :error, required
78
+ * *type*: :number, :date_time, :boolean, :string, :error, required
81
79
  * *value*: needs to respond to 'to_s'
82
80
 
83
81
 
@@ -119,7 +117,7 @@ These classes define how a spreadsheet cells are styled.
119
117
  * *pattern_color*: hex string
120
118
 
121
119
  === Xmlss::Style::NumberFormat
122
- * *format*: :symbol (see code for options)
120
+ * *format*: :symbol (there are MANY different options for this, I suggest saving a spreadsheet in the XML format and seeing what Excel uses)
123
121
 
124
122
  === Xmlss::Style::Protection
125
123
  * *protected*: bool, default: false
@@ -4,7 +4,7 @@ require 'test/env'
4
4
  class ExampleWorkbook < Xmlss::Workbook
5
5
  def initialize
6
6
  super
7
- puts "Builing #{self.name}.xml..."
7
+ puts "Building #{self.name}.xml..."
8
8
  build
9
9
  end
10
10
 
data/lib/xmlss/data.rb CHANGED
@@ -12,7 +12,7 @@ module Xmlss
12
12
  :value => :xml_value }
13
13
  end
14
14
 
15
- include Xmlss::Enum
15
+ include Enumeration
16
16
  enum :type, {
17
17
  :number => "Number",
18
18
  :date_time => "DateTime",
@@ -6,7 +6,7 @@ module Xmlss::Style
6
6
  :attributes => [:horizontal, :vertical, :wrap_text, :rotate] }
7
7
  end
8
8
 
9
- include Xmlss::Enum
9
+ include Enumeration
10
10
  enum :horizontal, {
11
11
  :automatic => "Automatic",
12
12
  :left => "Left",
@@ -6,7 +6,7 @@ module Xmlss::Style
6
6
  :attributes => [:color, :position, :weight, :line_style] }
7
7
  end
8
8
 
9
- include Xmlss::Enum
9
+ include Enumeration
10
10
  enum :position, {
11
11
  :left => "Left",
12
12
  :top => "Top",
@@ -9,7 +9,7 @@ module Xmlss::Style
9
9
  ] }
10
10
  end
11
11
 
12
- include Xmlss::Enum
12
+ include Enumeration
13
13
  enum :underline, {
14
14
  :none => 0,
15
15
  :single => 1,
@@ -6,7 +6,7 @@ module Xmlss::Style
6
6
  :attributes => [:color, :pattern, :pattern_color] }
7
7
  end
8
8
 
9
- include Xmlss::Enum
9
+ include Enumeration
10
10
  enum :pattern, {
11
11
  :none => "None",
12
12
  :solid => "Solid",
data/lib/xmlss/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Xmlss
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -16,8 +16,24 @@ module Xmlss
16
16
  attr_accessor :styles, :worksheets
17
17
 
18
18
  def initialize(attrs={})
19
- self.styles = Xmlss::ItemSet.new(:styles, attrs[:styles] || [])
20
- self.worksheets = Xmlss::ItemSet.new(nil, attrs[:worksheets] || [])
19
+ self.styles = attrs[:styles]
20
+ self.worksheets = attrs[:worksheets]
21
+ end
22
+
23
+ def styles=(collection)
24
+ @styles = if (set = collection || []).kind_of?(ItemSet)
25
+ set
26
+ else
27
+ ItemSet.new(:styles, set)
28
+ end
29
+ end
30
+
31
+ def worksheets=(collection)
32
+ @worksheets = if (set = collection || []).kind_of?(ItemSet)
33
+ set
34
+ else
35
+ ItemSet.new(nil, set)
36
+ end
21
37
  end
22
38
 
23
39
  def to_xml
@@ -13,11 +13,15 @@ module Xmlss
13
13
  attr_accessor :name, :table
14
14
 
15
15
  def initialize(name, attrs={})
16
- if name.nil? || name.empty?
16
+ self.name = name
17
+ self.table = attrs[:table] || Table.new
18
+ end
19
+
20
+ def name=(value)
21
+ if value.nil? || value.to_s.empty?
17
22
  raise ArgumentError, "'#{name.inspect}' is not a good name for a worksheet"
18
23
  end
19
- self.name = sanitized_name(name)
20
- self.table = attrs[:table] || Table.new
24
+ @name = sanitized_name(value.to_s)
21
25
  end
22
26
 
23
27
  def table=(value)
@@ -29,9 +33,9 @@ module Xmlss
29
33
 
30
34
  private
31
35
 
32
- def sanitized_name(value)
33
- # worksheet name cannot contain: /, \, ?, *, [, ]
34
- value.to_s.gsub(/[\/|\\|\?|\*|\[|\]]/, '')
36
+ def sanitized_name(name)
37
+ # worksheet name cannot contain: /, \, :, ;, * or start with '['
38
+ name.to_s.gsub(/[\/|\\|:|;|\*]/, '').gsub(/^\[/, '')
35
39
  end
36
40
  end
37
41
  end
data/lib/xmlss.rb CHANGED
@@ -24,8 +24,8 @@ module Xmlss
24
24
  end
25
25
  end
26
26
 
27
+ require 'enumeration'
27
28
  require 'xmlss/xml'
28
- require 'xmlss/enum'
29
29
  require 'xmlss/style/base'
30
30
  require 'xmlss/workbook'
31
31
 
@@ -17,7 +17,14 @@ module Xmlss
17
17
 
18
18
  context "when initializing with attrs" do
19
19
  subject do
20
- styles = [
20
+ # specifying attrs at init time
21
+ Workbook.new({
22
+ :worksheets => [Worksheet.new('sheet1')]
23
+ })
24
+ end
25
+ before do
26
+ # writing attrs at run time
27
+ subject.styles = [
21
28
  Xmlss::Style::Base.new('title') do
22
29
  alignment({:horizontal => :left})
23
30
  font({:size => 14, :bold => true})
@@ -31,10 +38,6 @@ module Xmlss
31
38
  end
32
39
  end
33
40
  ]
34
- Workbook.new({
35
- :worksheets => [Worksheet.new('sheet1')],
36
- :styles => styles
37
- })
38
41
  end
39
42
 
40
43
  should "build the attrs appropriately" do
@@ -17,12 +17,18 @@ module Xmlss
17
17
  end
18
18
 
19
19
  should "filter name chars" do
20
- # worksheet name cannot contain: /, \, ?, *, [, ]
20
+ # worksheet name cannot contain: /, \, :, ;, * or start with '['
21
21
  assert_equal "test test", Worksheet.new("test/ test").name
22
22
  assert_equal "test test", Worksheet.new("tes\\t test").name
23
- assert_equal "test test", Worksheet.new("te?st test?").name
24
- assert_equal "test test", Worksheet.new("t*est test").name
25
- assert_equal "test test", Worksheet.new("[te]st test").name
23
+ assert_equal "test test", Worksheet.new("te:st test:").name
24
+ ws = Worksheet.new("te;st ;test")
25
+ assert_equal "test test", ws.name
26
+ ws.name = "t*est test"
27
+ assert_equal "test test", ws.name
28
+ ws.name = "[te]st test"
29
+ assert_equal "te]st test", ws.name
30
+ ws.name = "t[e]st test"
31
+ assert_equal "t[e]st test", ws.name
26
32
  end
27
33
 
28
34
  should "allow defining a table at init" do
data/xmlss.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_development_dependency("bundler", ["~> 1.0"])
21
- s.add_development_dependency("test-belt", ["= 0.2.1"]) # locked to a specific version for test stability
21
+ s.add_development_dependency("test-belt", ["= 0.2.1"])
22
22
  s.add_dependency("nokogiri", ["~> 1.4.0"])
23
+ s.add_dependency("enumeration", ["~>1.1.0"])
23
24
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlss
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-14 00:00:00 -05:00
18
+ date: 2011-04-07 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -65,6 +65,22 @@ dependencies:
65
65
  version: 1.4.0
66
66
  type: :runtime
67
67
  version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: enumeration
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ hash: 19
77
+ segments:
78
+ - 1
79
+ - 1
80
+ - 0
81
+ version: 1.1.0
82
+ type: :runtime
83
+ version_requirements: *id004
68
84
  description: This gem provides an api for constructing spreadsheet data and then uses that data to generate xml that can be interpreted by MS Excel. The xml conforms to the XML Spreadsheet spec (http://msdn.microsoft.com/en-us/library/aa140066(office.10).aspx).
69
85
  email:
70
86
  - kelly@kelredd.com
@@ -89,7 +105,6 @@ files:
89
105
  - lib/xmlss/cell.rb
90
106
  - lib/xmlss/column.rb
91
107
  - lib/xmlss/data.rb
92
- - lib/xmlss/enum.rb
93
108
  - lib/xmlss/item_set.rb
94
109
  - lib/xmlss/row.rb
95
110
  - lib/xmlss/style/alignment.rb
@@ -107,7 +122,6 @@ files:
107
122
  - test/cell_test.rb
108
123
  - test/column_test.rb
109
124
  - test/data_test.rb
110
- - test/enum_test.rb
111
125
  - test/env.rb
112
126
  - test/helper.rb
113
127
  - test/item_set_test.rb
@@ -164,7 +178,6 @@ test_files:
164
178
  - test/cell_test.rb
165
179
  - test/column_test.rb
166
180
  - test/data_test.rb
167
- - test/enum_test.rb
168
181
  - test/env.rb
169
182
  - test/helper.rb
170
183
  - test/item_set_test.rb
data/lib/xmlss/enum.rb DELETED
@@ -1,56 +0,0 @@
1
- # common methods used for handling enum data
2
- module Xmlss
3
- module Enum
4
-
5
- module ClassMethods
6
- def enum(name, map)
7
- # TODO: validate name
8
- unless map.kind_of?(::Hash)
9
- raise ArguementError, "please specify the enum map as a Hash"
10
- end
11
-
12
- # define an anonymous Module to extend on
13
- # defining a class level map reader
14
- class_methods = Module.new do
15
- define_method(name) do |key|
16
- class_variable_get("@@#{name}")[key]
17
- end
18
- end
19
-
20
- # set a class variable to store the enum map (used by above reader)
21
- # extend the anonymous module to get tne above class
22
- # level reader for the map
23
- class_eval do
24
- class_variable_set("@@#{name}", map)
25
- extend class_methods
26
- end
27
-
28
- # instance writer for the enum value
29
- define_method("#{name}=") do |value|
30
- map = self.class.send(:class_variable_get, "@@#{name}")
31
- instance_variable_set("@#{name}", if value && map.has_key?(value)
32
- # write by key
33
- map[value]
34
- elsif map.has_value?(value)
35
- # write by value
36
- value
37
- else
38
- nil
39
- end)
40
- end
41
-
42
- # instance reader for the enum value
43
- define_method(name) do
44
- instance_variable_get("@#{name}")
45
- end
46
- end
47
- end
48
-
49
- class << self
50
- def included(receiver)
51
- receiver.send :extend, ClassMethods
52
- end
53
- end
54
-
55
- end
56
- end
data/test/enum_test.rb DELETED
@@ -1,63 +0,0 @@
1
- require "test/helper"
2
- require 'xmlss/enum'
3
- require 'test/thing'
4
-
5
- module Xmlss
6
- class EnumTest < Test::Unit::TestCase
7
-
8
- context "Xmlss::Enum mixin" do
9
- subject { Thing.new }
10
- before do
11
- Thing.send :include, Xmlss::Enum
12
- end
13
-
14
- should_have_class_method :enum
15
-
16
- context "instance" do
17
- before do
18
- Thing.send(:enum, :stuff, {
19
- :a => "eh",
20
- :b => "bee",
21
- :c => "see"
22
- })
23
- end
24
-
25
- should_have_class_method :stuff
26
- should "provide class level access to the enum" do
27
- assert Thing.send(:class_variable_get, "@@stuff")
28
- assert_equal 3, Thing.send(:class_variable_get, "@@stuff").size
29
- assert_equal "eh", Thing.stuff(:a)
30
- end
31
-
32
- should_have_accessor :stuff
33
-
34
- should "write by key and read by value" do
35
- subject.stuff = :a
36
- assert_equal "eh", subject.stuff
37
- end
38
-
39
- should "write by value and read by value" do
40
- subject.stuff = "bee"
41
- assert_equal "bee", subject.stuff
42
- end
43
-
44
- should "not read by key" do
45
- subject.stuff = :c
46
- assert_not_equal :c, subject.stuff
47
- end
48
-
49
- should "write nil for keys that aren't in the enum" do
50
- subject.stuff = :bad
51
- assert_equal nil, subject.stuff
52
- end
53
-
54
- should "write nil for values that aren't in the enum" do
55
- subject.stuff = "bady-bad"
56
- assert_equal nil, subject.stuff
57
- end
58
-
59
- end
60
- end
61
-
62
- end
63
- end