xmlss 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +1 -2
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +12 -11
  4. data/README.rdoc +141 -107
  5. data/Rakefile +24 -1
  6. data/bench/profiler.rb +6 -0
  7. data/bench/profiler_runner.rb +43 -0
  8. data/examples/example_workbook.rb +8 -12
  9. data/examples/layout.rb +34 -60
  10. data/examples/layout.xml +66 -0
  11. data/examples/simple.rb +16 -21
  12. data/examples/simple.xml +32 -0
  13. data/examples/styles.rb +52 -56
  14. data/examples/styles.xml +50 -0
  15. data/examples/text.rb +18 -28
  16. data/examples/text.xml +20 -0
  17. data/lib/xmlss/{cell.rb → element/cell.rb} +4 -14
  18. data/lib/xmlss/{column.rb → element/column.rb} +2 -7
  19. data/lib/xmlss/{data.rb → element/data.rb} +7 -12
  20. data/lib/xmlss/{row.rb → element/row.rb} +2 -13
  21. data/lib/xmlss/{worksheet.rb → element/worksheet.rb} +7 -18
  22. data/lib/xmlss/style/alignment.rb +3 -10
  23. data/lib/xmlss/style/base.rb +6 -45
  24. data/lib/xmlss/style/border.rb +5 -5
  25. data/lib/xmlss/style/font.rb +2 -9
  26. data/lib/xmlss/style/interior.rb +2 -5
  27. data/lib/xmlss/style/number_format.rb +4 -7
  28. data/lib/xmlss/style/protection.rb +4 -7
  29. data/lib/xmlss/undies_writer.rb +172 -0
  30. data/lib/xmlss/version.rb +1 -1
  31. data/lib/xmlss/workbook.rb +97 -31
  32. data/lib/xmlss.rb +1 -28
  33. data/test/{cell_test.rb → element/cell_test.rb} +11 -35
  34. data/test/{column_test.rb → element/column_test.rb} +6 -12
  35. data/test/{data_test.rb → element/data_test.rb} +15 -10
  36. data/test/{row_test.rb → element/row_test.rb} +5 -35
  37. data/test/{worksheet_test.rb → element/worksheet_test.rb} +4 -30
  38. data/test/helper.rb +13 -30
  39. data/test/style/alignment_test.rb +13 -45
  40. data/test/style/base_test.rb +1 -106
  41. data/test/style/border_test.rb +12 -32
  42. data/test/style/font_test.rb +11 -43
  43. data/test/style/interior_test.rb +7 -27
  44. data/test/style/number_format_test.rb +5 -21
  45. data/test/style/protection_test.rb +2 -12
  46. data/test/undies_writer_test.rb +333 -0
  47. data/test/workbook_test.rb +89 -44
  48. data/xmlss.gemspec +2 -2
  49. metadata +37 -39
  50. data/lib/xmlss/item_set.rb +0 -17
  51. data/lib/xmlss/table.rb +0 -22
  52. data/lib/xmlss/xml.rb +0 -60
  53. data/test/item_set_test.rb +0 -27
  54. data/test/table_test.rb +0 -56
  55. data/test/xml_test.rb +0 -81
  56. data/test/xmlss_test.rb +0 -31
@@ -0,0 +1,32 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
3
+ <Styles>
4
+ </Styles>
5
+
6
+ <Worksheet ss:Name="1 row, 5 columns">
7
+ <Table>
8
+ <Column />
9
+ <Column />
10
+ <Column />
11
+ <Column />
12
+ <Column />
13
+ <Row>
14
+ <Cell>
15
+ <Data ss:Type="Number">1</Data>
16
+ </Cell>
17
+ <Cell>
18
+ <Data ss:Type="String">text</Data>
19
+ </Cell>
20
+ <Cell>
21
+ <Data ss:Type="Number">123.45</Data>
22
+ </Cell>
23
+ <Cell>
24
+ <Data ss:Type="String">0001267</Data>
25
+ </Cell>
26
+ <Cell>
27
+ <Data ss:Type="String">$45.23</Data>
28
+ </Cell>
29
+ </Row>
30
+ </Table>
31
+ </Worksheet>
32
+ </Workbook>
data/examples/styles.rb CHANGED
@@ -1,55 +1,54 @@
1
1
  require 'examples/example_workbook'
2
2
 
3
- class Styles < ExampleWorkbook
4
- def name; "styles"; end
5
- def build
3
+ # $ bundle exec ruby examples/styles.rb
6
4
 
7
- wksht = Xmlss::Worksheet.new('styles')
8
- wksht.table.columns << Xmlss::Column.new
5
+ ExampleWorkbook.new("styles") do
9
6
 
10
- self.styles << Xmlss::Style::Base.new('centered') do
11
- alignment(
12
- :horizontal => :center,
13
- :vertical => :center
14
- )
7
+ worksheet 'styles' do
8
+ column
9
+
10
+ style 'centered' do
11
+ alignment(:horizontal => :center, :vertical => :center)
15
12
  end
16
- wksht.table.rows << Xmlss::Row.new
17
- wksht.table.rows[0].cells << Xmlss::Cell.new({
18
- :style_id => "centered",
19
- :data => Xmlss::Data.new("x")
20
- })
21
13
 
22
- self.styles << Xmlss::Style::Base.new('bordered') do
14
+ row {
15
+ cell(:style_id => "centered") { data "x" }
16
+ }
17
+
18
+ style 'bordered' do
23
19
  alignment(:wrap_text => true)
24
- border(
25
- :position => :top,
26
- :weight => :hairline,
27
- :line_style => :continuous
28
- )
29
- border(
30
- :position => :right,
31
- :weight => :medium,
32
- :line_style => :continuous
33
- )
34
- border(
35
- :position => :bottom,
36
- :weight => :thick,
37
- :line_style => :dash_dot,
38
- :color => '#00FF00'
39
- )
40
- border(
41
- :position => :left,
42
- :weight => :thin,
43
- :line_style => :dot
44
- )
20
+ borders {
21
+ border(
22
+ :position => :top,
23
+ :weight => :hairline,
24
+ :line_style => :continuous
25
+ )
26
+ border(
27
+ :position => :right,
28
+ :weight => :medium,
29
+ :line_style => :continuous
30
+ )
31
+ border(
32
+ :position => :bottom,
33
+ :weight => :thick,
34
+ :line_style => :dash_dot,
35
+ :color => '#00FF00'
36
+ )
37
+ border(
38
+ :position => :left,
39
+ :weight => :thin,
40
+ :line_style => :dot
41
+ )
42
+ }
45
43
  end
46
- wksht.table.rows << Xmlss::Row.new
47
- wksht.table.rows[1].cells << Xmlss::Cell.new({
48
- :style_id => "bordered",
49
- :data => Xmlss::Data.new(%{blah blah blah blah blah\nblah blah blah blah\nblah blah blah blah})
50
- })
51
44
 
52
- self.styles << Xmlss::Style::Base.new('fonted') do
45
+ row {
46
+ cell(:style_id => "bordered") {
47
+ data %{blah blah blah blah blah\nblah blah blah blah\nblah blah blah blah}
48
+ }
49
+ }
50
+
51
+ style 'fonted' do
53
52
  font(
54
53
  :bold => true,
55
54
  :color => "#FF0000",
@@ -59,13 +58,12 @@ class Styles < ExampleWorkbook
59
58
  :underline => true
60
59
  )
61
60
  end
62
- wksht.table.rows << Xmlss::Row.new
63
- wksht.table.rows[2].cells << Xmlss::Cell.new({
64
- :style_id => "fonted",
65
- :data => Xmlss::Data.new("Cool Font Styles!!")
66
- })
67
61
 
68
- self.styles << Xmlss::Style::Base.new('interior') do
62
+ row {
63
+ cell(:style_id => "fonted") { data "Cool Font Styles!!" }
64
+ }
65
+
66
+ style 'interior' do
69
67
  interior(
70
68
  :color => "#FF0000",
71
69
  :pattern => :diag_cross,
@@ -73,13 +71,11 @@ class Styles < ExampleWorkbook
73
71
  )
74
72
  font(:color => "#FFFFFF")
75
73
  end
76
- wksht.table.rows << Xmlss::Row.new
77
- wksht.table.rows[3].cells << Xmlss::Cell.new({
78
- :style_id => "interior",
79
- :data => Xmlss::Data.new("Weird Styles Man...")
80
- })
81
74
 
82
- self.worksheets << wksht
75
+ row {
76
+ cell(:style_id => "interior") { data "Weird Styles Man..." }
77
+ }
78
+
83
79
  end
80
+
84
81
  end
85
- Styles.new.to_file(:format)
@@ -0,0 +1,50 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
3
+ <Styles>
4
+ <Style ss:ID="centered">
5
+ <Alignment ss:Horizontal="Center" ss:Vertical="Center" />
6
+ </Style>
7
+ <Style ss:ID="bordered">
8
+ <Alignment ss:WrapText="1" />
9
+ <Borders>
10
+ <Border ss:LineStyle="Continuous" ss:Position="Top" ss:Weight="0" />
11
+ <Border ss:LineStyle="Continuous" ss:Position="Right" ss:Weight="2" />
12
+ <Border ss:Color="#00FF00" ss:LineStyle="DashDot" ss:Position="Bottom" ss:Weight="3" />
13
+ <Border ss:LineStyle="Dot" ss:Position="Left" ss:Weight="1" />
14
+ </Borders>
15
+ </Style>
16
+ <Style ss:ID="fonted">
17
+ <Font ss:Bold="1" ss:Color="#FF0000" ss:Italic="1" ss:Size="18" ss:StrikeThrough="1" />
18
+ </Style>
19
+ <Style ss:ID="interior">
20
+ <Interior ss:Color="#FF0000" ss:Pattern="DiagCross" ss:PatternColor="#00FFFF" />
21
+ <Font ss:Color="#FFFFFF" />
22
+ </Style>
23
+ </Styles>
24
+
25
+ <Worksheet ss:Name="styles">
26
+ <Table>
27
+ <Column />
28
+ <Row>
29
+ <Cell ss:StyleID="centered">
30
+ <Data ss:Type="String">x</Data>
31
+ </Cell>
32
+ </Row>
33
+ <Row>
34
+ <Cell ss:StyleID="bordered">
35
+ <Data ss:Type="String">blah blah blah blah blah&#13;&#10;blah blah blah blah&#13;&#10;blah blah blah blah</Data>
36
+ </Cell>
37
+ </Row>
38
+ <Row>
39
+ <Cell ss:StyleID="fonted">
40
+ <Data ss:Type="String">Cool Font Styles!!</Data>
41
+ </Cell>
42
+ </Row>
43
+ <Row>
44
+ <Cell ss:StyleID="interior">
45
+ <Data ss:Type="String">Weird Styles Man...</Data>
46
+ </Cell>
47
+ </Row>
48
+ </Table>
49
+ </Worksheet>
50
+ </Workbook>
data/examples/text.rb CHANGED
@@ -1,36 +1,26 @@
1
1
  require 'examples/example_workbook'
2
2
 
3
- class Text < ExampleWorkbook
4
- def name; "text"; end
5
- def build
3
+ # $ bundle exec ruby examples/text.rb
6
4
 
7
- # add in general text style
8
- self.styles << Xmlss::Style::Base.new('general_text') do
9
- alignment(
10
- :horizontal => :left,
11
- :vertical => :top,
12
- :wrap_text => true
13
- )
14
- number_format(
15
- :format => "@" # set format to text explicitly
16
- )
17
- end
5
+ ExampleWorkbook.new("text") do
18
6
 
19
- # add single cell with text data and specify general text style
20
- wksht = Xmlss::Worksheet.new('text')
21
- wksht.table.columns << Xmlss::Column.new
22
- row1 = Xmlss::Row.new
23
- row1.cells << Xmlss::Cell.new({
24
- :style_id => "general_text",
25
- :data => Xmlss::Data.new(%{
7
+ style 'general_text' do
8
+ alignment(:horizontal => :left, :vertical => :top, :wrap_text => true)
9
+ # set format to text explicitly
10
+ number_format("@")
11
+ end
12
+
13
+ worksheet('text') do
14
+ column
15
+
16
+ row {
17
+ cell(:style_id => "general_text") {
18
+ data %{
26
19
  A blob of text
27
20
  with line breaks
28
- and leading space
29
- })
30
- })
31
- wksht.table.rows << row1
32
- self.worksheets << wksht
33
-
21
+ and leading space}
22
+ }
23
+ }
34
24
  end
25
+
35
26
  end
36
- Text.new.to_file(:format)
data/examples/text.xml ADDED
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
3
+ <Styles>
4
+ <Style ss:ID="general_text">
5
+ <Alignment ss:Horizontal="Left" ss:Vertical="Top" ss:WrapText="1" />
6
+ <NumberFormat ss:Format="@" />
7
+ </Style>
8
+ </Styles>
9
+
10
+ <Worksheet ss:Name="text">
11
+ <Table>
12
+ <Column />
13
+ <Row>
14
+ <Cell ss:StyleID="general_text">
15
+ <Data ss:Type="String">&#13;&#10;A blob of text&#13;&#10;with line breaks&#13;&#10; and leading space</Data>
16
+ </Cell>
17
+ </Row>
18
+ </Table>
19
+ </Worksheet>
20
+ </Workbook>
@@ -1,28 +1,18 @@
1
- require 'xmlss/data'
2
-
3
- module Xmlss
1
+ module Xmlss; end
2
+ module Xmlss::Element
4
3
  class Cell
5
4
 
6
- include Xmlss::Xml
7
- def xml
8
- { :node => :cell,
9
- :attributes => [:index, :style_i_d, :formula, :h_ref, :merge_across, :merge_down],
10
- :children => [:data] }
11
- end
12
-
13
- attr_accessor :style_id, :formula, :href, :merge_across, :merge_down
14
- attr_accessor :index, :data
5
+ attr_accessor :index, :style_id, :formula, :href, :merge_across, :merge_down
15
6
  alias_method :style_i_d, :style_id
16
7
  alias_method :h_ref, :href
17
8
 
18
- def initialize(attrs={})
9
+ def initialize(attrs={}, &build)
19
10
  self.index = attrs[:index]
20
11
  self.style_id = attrs[:style_id]
21
12
  self.formula = attrs[:formula]
22
13
  self.href = attrs[:href]
23
14
  self.merge_across = attrs[:merge_across] || 0
24
15
  self.merge_down = attrs[:merge_down] || 0
25
- self.data = attrs[:data]
26
16
  end
27
17
 
28
18
  [:index, :merge_across, :merge_down].each do |meth|
@@ -1,12 +1,7 @@
1
- module Xmlss
1
+ module Xmlss; end
2
+ module Xmlss::Element
2
3
  class Column
3
4
 
4
- include Xmlss::Xml
5
- def xml
6
- { :node => :column,
7
- :attributes => [:style_i_d, :width, :auto_fit_width, :hidden] }
8
- end
9
-
10
5
  attr_accessor :style_id, :width, :auto_fit_width, :hidden
11
6
  alias_method :style_i_d, :style_id
12
7
 
@@ -1,17 +1,12 @@
1
1
  require 'date'
2
+ require 'enumeration'
2
3
 
3
- module Xmlss
4
+ module Xmlss; end
5
+ module Xmlss::Element
4
6
  class Data
5
7
 
6
8
  LB = "&#13;&#10;"
7
9
 
8
- include Xmlss::Xml
9
- def xml
10
- { :node => :data,
11
- :attributes => [:type],
12
- :value => :xml_value }
13
- end
14
-
15
10
  include Enumeration
16
11
  enum :type, {
17
12
  :number => "Number",
@@ -36,13 +31,13 @@ module Xmlss
36
31
  end
37
32
 
38
33
  def xml_value
39
- case value
34
+ case self.value
40
35
  when ::Date, ::Time, ::DateTime
41
- value.strftime("%Y-%m-%dT%H:%M:%S")
36
+ self.value.strftime("%Y-%m-%dT%H:%M:%S")
42
37
  when ::String, ::Symbol
43
- value.to_s.gsub(/(\r|\n)+/, LB)
38
+ self.value.to_s.gsub(/(\r|\n)+/, LB)
44
39
  else
45
- value.to_s
40
+ self.value.to_s
46
41
  end
47
42
  end
48
43
 
@@ -1,18 +1,8 @@
1
- require 'xmlss/item_set'
2
- require 'xmlss/cell'
3
-
4
- module Xmlss
1
+ module Xmlss; end
2
+ module Xmlss::Element
5
3
  class Row
6
4
 
7
- include Xmlss::Xml
8
- def xml
9
- { :node => :row,
10
- :attributes => [:style_i_d, :height, :auto_fit_height, :hidden],
11
- :children => [:cells] }
12
- end
13
-
14
5
  attr_accessor :style_id, :height, :auto_fit_height, :hidden
15
- attr_accessor :cells
16
6
  alias_method :style_i_d, :style_id
17
7
 
18
8
  def initialize(attrs={})
@@ -20,7 +10,6 @@ module Xmlss
20
10
  self.height = attrs[:height]
21
11
  self.auto_fit_height = attrs[:auto_fit_height] || false
22
12
  self.hidden = attrs[:hidden] || false
23
- self.cells = Xmlss::ItemSet.new(nil, attrs[:cells] || [])
24
13
  end
25
14
 
26
15
  def height=(value)
@@ -1,20 +1,16 @@
1
- require 'xmlss/table'
1
+ require 'xmlss/element/column'
2
+ require 'xmlss/element/row'
3
+ require 'xmlss/element/cell'
4
+ require 'xmlss/element/data'
2
5
 
3
- module Xmlss
6
+ module Xmlss; end
7
+ module Xmlss::Element
4
8
  class Worksheet
5
9
 
6
- include Xmlss::Xml
7
- def xml
8
- { :node => :worksheet,
9
- :attributes => [:name],
10
- :children => [:table] }
11
- end
12
-
13
- attr_accessor :name, :table
10
+ attr_accessor :name
14
11
 
15
12
  def initialize(name, attrs={})
16
13
  self.name = name
17
- self.table = attrs[:table] || Table.new
18
14
  end
19
15
 
20
16
  def name=(value)
@@ -24,13 +20,6 @@ module Xmlss
24
20
  @name = sanitized_name(value.to_s)
25
21
  end
26
22
 
27
- def table=(value)
28
- if value.nil? || !value.kind_of?(Table)
29
- raise ArgumentError, "you must set table to an actual Table object"
30
- end
31
- @table = value
32
- end
33
-
34
23
  private
35
24
 
36
25
  def sanitized_name(name)
@@ -1,10 +1,7 @@
1
+ require 'xmlss/style/base'
2
+
1
3
  module Xmlss::Style
2
4
  class Alignment
3
- include Xmlss::Xml
4
- def xml
5
- { :node => :alignment,
6
- :attributes => [:horizontal, :vertical, :wrap_text, :rotate] }
7
- end
8
5
 
9
6
  include Enumeration
10
7
  enum :horizontal, {
@@ -33,11 +30,7 @@ module Xmlss::Style
33
30
 
34
31
  def rotate=(value)
35
32
  @rotate = if value.kind_of?(::Numeric)
36
- if value <= 90 && value >= -90
37
- value.round
38
- else
39
- nil
40
- end
33
+ value <= 90 && value >= -90 ? value.round : nil
41
34
  else
42
35
  nil
43
36
  end
@@ -1,4 +1,7 @@
1
- require 'xmlss/item_set'
1
+ module Xmlss;end
2
+ module Xmlss::Style; end
3
+
4
+ require 'enumeration'
2
5
  require 'xmlss/style/alignment'
3
6
  require 'xmlss/style/border'
4
7
  require 'xmlss/style/font'
@@ -8,56 +11,14 @@ require 'xmlss/style/protection'
8
11
 
9
12
  module Xmlss::Style
10
13
  class Base
11
- include Xmlss::Xml
12
- def xml
13
- { :node => :style,
14
- :attributes => [:i_d],
15
- :children => [
16
- :alignment, :borders, :font, :interior, :number_format, :protection
17
- ]}
18
- end
19
14
 
20
- attr_reader :id, :borders
15
+ attr_reader :id
21
16
  alias_method :i_d, :id
22
- attr_writer :alignment, :font, :interior, :number_format, :protection
23
17
 
24
- def initialize(id, &block)
18
+ def initialize(id)
25
19
  raise ArgumentError, "please choose an id for the style" if id.nil?
26
20
  @id = id.to_s
27
- self.borders = Xmlss::ItemSet.new(:borders)
28
- instance_eval(&block) if block
29
- end
30
-
31
- def borders=(value)
32
- if !value.kind_of? Xmlss::ItemSet
33
- raise ArgumentError, "must set borders to an Xmlss::ItemSet value"
34
- end
35
- @borders = value
36
- end
37
-
38
- def border(opts = nil)
39
- valid_attrs?(opts) do |attrs|
40
- @borders << Border.new(attrs)
41
- end
42
21
  end
43
22
 
44
- [:alignment, :font, :interior, :number_format, :protection].each do |meth|
45
- define_method(meth) do |*args|
46
- valid_attrs?(args.first) do |attrs|
47
- instance_variable_set("@#{meth}", klass(meth).new(attrs))
48
- end
49
- instance_variable_get("@#{meth}")
50
- end
51
- end
52
-
53
- protected
54
-
55
- def valid_attrs?(attrs)
56
- yield attrs if block_given? && attrs && attrs.kind_of?(::Hash)
57
- end
58
-
59
- def klass(method_name)
60
- Xmlss::Style.const_get(Xmlss.classify(method_name))
61
- end
62
23
  end
63
24
  end
@@ -1,12 +1,10 @@
1
+ require 'xmlss/style/base'
2
+
1
3
  module Xmlss::Style
2
4
  class Border
3
- include Xmlss::Xml
4
- def xml
5
- { :node => :border,
6
- :attributes => [:color, :position, :weight, :line_style] }
7
- end
8
5
 
9
6
  include Enumeration
7
+
10
8
  enum :position, {
11
9
  :left => "Left",
12
10
  :top => "Top",
@@ -15,12 +13,14 @@ module Xmlss::Style
15
13
  :diagonal_left => "DiagonalLeft",
16
14
  :diagonal_right => "DiagonalRight"
17
15
  }
16
+
18
17
  enum :weight, {
19
18
  :hairline => 0,
20
19
  :thin => 1,
21
20
  :medium => 2,
22
21
  :thick => 3
23
22
  }
23
+
24
24
  enum :line_style, {
25
25
  :none => "None",
26
26
  :continuous => "Continuous",
@@ -1,14 +1,7 @@
1
+ require 'xmlss/style/base'
2
+
1
3
  module Xmlss::Style
2
4
  class Font
3
- include Xmlss::Xml
4
- def xml
5
- { :node => :font,
6
- :attributes => [
7
- :bold, :color, :italic, :size, :shadow,
8
- :strike_through, :underline, :vertical_align,
9
- :font_name
10
- ] }
11
- end
12
5
 
13
6
  include Enumeration
14
7
  enum :underline, {
@@ -1,10 +1,7 @@
1
+ require 'xmlss/style/base'
2
+
1
3
  module Xmlss::Style
2
4
  class Interior
3
- include Xmlss::Xml
4
- def xml
5
- { :node => :interior,
6
- :attributes => [:color, :pattern, :pattern_color] }
7
- end
8
5
 
9
6
  include Enumeration
10
7
  enum :pattern, {
@@ -1,15 +1,12 @@
1
+ require 'xmlss/style/base'
2
+
1
3
  module Xmlss::Style
2
4
  class NumberFormat
3
- include Xmlss::Xml
4
- def xml
5
- { :node => :number_format,
6
- :attributes => [:format] }
7
- end
8
5
 
9
6
  attr_accessor :format
10
7
 
11
- def initialize(attrs={})
12
- self.format = attrs[:format]
8
+ def initialize(format=nil)
9
+ self.format = format
13
10
  end
14
11
 
15
12
  def format=(value)
@@ -1,15 +1,12 @@
1
+ require 'xmlss/style/base'
2
+
1
3
  module Xmlss::Style
2
4
  class Protection
3
- include Xmlss::Xml
4
- def xml
5
- { :node => :protection,
6
- :attributes => [:protect] }
7
- end
8
5
 
9
6
  attr_accessor :protect
10
7
 
11
- def initialize(attrs={})
12
- self.protect = attrs[:protect] || false
8
+ def initialize(value=nil)
9
+ self.protect = value
13
10
  end
14
11
 
15
12
  def protected?; !!self.protect; end