pauldix-sax-machine 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sax-machine.rb CHANGED
@@ -7,5 +7,5 @@ require "sax-machine/sax_handler"
7
7
  require "sax-machine/sax_config"
8
8
 
9
9
  module SAXMachine
10
- VERSION = "0.0.3"
10
+ VERSION = "0.0.4"
11
11
  end
@@ -0,0 +1,33 @@
1
+ module SAXMachine
2
+ class SAXConfig
3
+
4
+ class CollectionConfig
5
+ attr_reader :name
6
+
7
+ def initialize(name, options)
8
+ @name = name.to_s
9
+ @class = options[:class]
10
+ @as = options[:as].to_s
11
+ end
12
+
13
+ def handler
14
+ SAXHandler.new(@class.new)
15
+ end
16
+
17
+ def accessor
18
+ as
19
+ end
20
+
21
+ protected
22
+
23
+ def as
24
+ @as
25
+ end
26
+
27
+ def class
28
+ @class || @name
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,48 @@
1
+ module SAXMachine
2
+ class SAXConfig
3
+
4
+ class ElementConfig
5
+ attr_reader :name
6
+
7
+ def initialize(name, options)
8
+ @name = name.to_s
9
+
10
+ if options.has_key?(:with)
11
+ # for faster comparisons later
12
+ @with = options[:with].to_a.flatten.collect {|o| o.to_s}
13
+ else
14
+ @with = nil
15
+ end
16
+
17
+ if options.has_key?(:value)
18
+ @value = options[:value].to_s
19
+ else
20
+ @value = nil
21
+ end
22
+
23
+ @as = options[:as]
24
+ end
25
+
26
+ def value_from_attrs(attrs)
27
+ attrs[attrs.index(@value) + 1]
28
+ end
29
+
30
+ def setter
31
+ "#{@as}="
32
+ end
33
+
34
+ def attrs_match?(attrs)
35
+ if @with
36
+ @with == (@with & attrs)
37
+ else
38
+ true
39
+ end
40
+ end
41
+
42
+ def has_value_and_attrs_match?(attrs)
43
+ !@value.nil? && attrs_match?(attrs)
44
+ end
45
+ end
46
+
47
+ end
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pauldix-sax-machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix
@@ -32,6 +32,8 @@ extra_rdoc_files: []
32
32
  files:
33
33
  - lib/sax-machine.rb
34
34
  - lib/sax-machine/sax_config.rb
35
+ - lib/sax-machine/sax_collection_config.rb
36
+ - lib/sax-machine/sax_element_config.rb
35
37
  - lib/sax-machine/sax_document.rb
36
38
  - lib/sax-machine/sax_handler.rb
37
39
  - README.rdoc