saxaphone 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  module Saxaphone
2
4
  class Element
3
5
  @@base_class_name = 'Saxaphone::Element'
@@ -28,10 +30,18 @@ module Saxaphone
28
30
  element_handlers[element_name] = ElementHandler.new(class_name, block)
29
31
  end
30
32
 
33
+ def store_attributes(*attribute_names)
34
+ @stored_attributes = attribute_names.flatten.to_set
35
+ end
36
+
31
37
  def element_handlers
32
38
  @element_handlers ||= {}
33
39
  end
34
40
 
41
+ def stored_attributes
42
+ @stored_attributes ||= Set.new
43
+ end
44
+
35
45
  def parse(xml)
36
46
  Saxaphone::Document.parse(xml, self)
37
47
  end
@@ -41,7 +51,7 @@ module Saxaphone
41
51
  def initialize(name = '', content = '', attribute_array = [])
42
52
  self.name = name
43
53
  self.content = content
44
- self.attributes = Hash[attribute_array]
54
+ self.attributes = Hash[attribute_array.select { |(key, value)| self.class.stored_attributes.include?(key) }]
45
55
  setup
46
56
  end
47
57
 
@@ -16,11 +16,14 @@ class Saxaphone::ElementTest < MiniTest::Spec
16
16
  assert_equal 'hola', element.setup_attr
17
17
  end
18
18
 
19
- def test_initialize
20
- element = Saxaphone::Element.new('foo', 'bar', [['a', 'b']])
19
+ def test_initialize_with_attributes
20
+ element = Class.new(Saxaphone::Element) do
21
+ store_attributes 'a', 'm'
22
+ end.new('foo', 'bar', [['a', 'b'], ['m', 'n'], ['x', 'y']])
23
+
21
24
  assert_equal 'foo', element.name
22
25
  assert_equal 'bar', element.content
23
- assert_equal({'a' => 'b'}, element.attributes)
26
+ assert_equal({'a' => 'b', 'm' => 'n'}, element.attributes)
24
27
  end
25
28
 
26
29
  def test_element_attributes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saxaphone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
17
- requirement: &2156448040 !ruby/object:Gem::Requirement
17
+ requirement: &2162445820 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2156448040
25
+ version_requirements: *2162445820
26
26
  description: Use objects
27
27
  email: developer@matthewhiggins.com
28
28
  executables: []