ox 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ox might be problematic. Click here for more details.

data/lib/ox.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # Copyright (c) 2011, Peter Ohler<br>
2
2
  # All rights reserved.
3
3
 
4
+ #
4
5
  # === Description:
5
6
  #
6
7
  # Ox handles XML documents in two ways. It is a generic XML parser and writer as
@@ -11,8 +11,12 @@ module Ox
11
11
  # The initializer can take multiple arguments in the form of key values
12
12
  # where the key is the variable name and the value is the variable
13
13
  # value. This is intended for testing purposes only.
14
- # @example Ox::Bag.new(:@x => 42, :@y => 57)
15
- # @param [Hash] args instance variable symbols and their values
14
+ # - +args+ [Hash] instance variable symbols and their values
15
+ #
16
+ # *Example*
17
+ #
18
+ # Ox::Bag.new(:@x => 42, :@y => 57)
19
+ #
16
20
  def initialize(args={ })
17
21
  args.each do |k,v|
18
22
  self.instance_variable_set(k, v)
@@ -20,9 +24,9 @@ module Ox
20
24
  end
21
25
 
22
26
  # Replaces the Object.respond_to?() method.
23
- # @param [Symbol] m method symbol
24
- # @return [Boolean] true for any method that matches an instance
25
- # variable reader, otherwise false.
27
+ # - +m+ [Symbol] method symbol
28
+ # *return* [Boolean] true for any method that matches an instance variable
29
+ # reader, otherwise false.
26
30
  def respond_to?(m)
27
31
  return true if super
28
32
  at_m = ('@' + m.to_s).to_sym
@@ -31,10 +35,12 @@ module Ox
31
35
 
32
36
  # Handles requests for variable values. Others cause an Exception to be
33
37
  # raised.
34
- # @param [Symbol] m method symbol
35
- # @return [Boolean] the value of the specified instance variable.
36
- # @raise [ArgumentError] if an argument is given. Zero arguments expected.
37
- # @raise [NoMethodError] if the instance variable is not defined.
38
+ # - +m+ (Symbol) method symbol
39
+ # *return* [Boolean] the value of the specified instance variable.
40
+ #
41
+ # _raise_ [ArgumentError] if an argument is given. Zero arguments expected.
42
+ #
43
+ # _raise_ [NoMethodError] if the instance variable is not defined.
38
44
  def method_missing(m, *args, &block)
39
45
  raise ArgumentError.new("wrong number of arguments (#{args.size} for 0) to method #{m}") unless args.nil? or args.empty?
40
46
  at_m = ('@' + m.to_s).to_sym
@@ -43,8 +49,8 @@ module Ox
43
49
  end
44
50
 
45
51
  # Replaces eql?() with something more reasonable for this Class.
46
- # @param [Object] other Object to compare self to
47
- # @return [Boolean] true if each variable and value are the same, otherwise false.
52
+ # - +other+ [Object] Object to compare self to
53
+ # *return* [Boolean] true if each variable and value are the same, otherwise false.
48
54
  def eql?(other)
49
55
  return false if (other.nil? or self.class != other.class)
50
56
  ova = other.instance_variables
@@ -61,9 +67,10 @@ module Ox
61
67
  # the Ox module and is available to service wrappers that receive XML
62
68
  # requests that include Objects of Classes not defined in the storage
63
69
  # process.
64
- # @param [String] classname Class name or symbol that includes Module names.
65
- # @return [Object] an instance of the specified Class.
66
- # @raise [NameError] if the classname is invalid.
70
+ # - +classname+ (String) Class name or symbol that includes Module names.
71
+ # *return* [Object] an instance of the specified Class.
72
+ #
73
+ # _raise_ [NameError] if the classname is invalid.
67
74
  def self.define_class(classname)
68
75
  classname = classname.to_s unless classname.is_a?(String)
69
76
  tokens = classname.split('::').map { |n| n.to_sym }
@@ -3,7 +3,7 @@ module Ox
3
3
  # CData represents a CDATA element in an XML document.
4
4
  class CData < Node
5
5
  # Creates a CDATA element.
6
- # @param value [String] value for the CDATA contents
6
+ # - +value+ [String] value for the CDATA contents
7
7
  def initialize(value)
8
8
  super
9
9
  end
@@ -4,7 +4,7 @@ module Ox
4
4
  # attribute only.
5
5
  class Comment < Node
6
6
  # Creates a new Comment with the specified value.
7
- # @param value [String] string value for the comment
7
+ # - +value+ [String] string value for the comment
8
8
  def initialize(value)
9
9
  super
10
10
  end
@@ -4,7 +4,7 @@ module Ox
4
4
  class DocType < Node
5
5
  # Creates a DOCTYPE elements with the content as a string specified in the
6
6
  # value parameter.
7
- # @param value [String] string value for the element
7
+ # - +value+ [String] string value for the element
8
8
  def initialize(value)
9
9
  super
10
10
  end
@@ -4,10 +4,10 @@ module Ox
4
4
  # the XML prolog. A Document includes Elements.
5
5
  class Document < Element
6
6
  # Create a new Document.
7
- # @param [Hash] prolog prolog attributes
8
- # @option prolog [String] :version version, typically '1.0' or '1.1'
9
- # @option prolog [String] :encoding encoding for the document, currently included but ignored
10
- # @option prolog [String] :standalone indicates the document is standalone
7
+ # - +prolog+ [Hash] prolog attributes
8
+ # - _:version_ [String] version, typically '1.0' or '1.1'
9
+ # - _:encoding_ [String] encoding for the document, currently included but ignored
10
+ # - _:standalone_ [String] indicates the document is standalone
11
11
  def initialize(prolog={})
12
12
  super(nil)
13
13
  @attributes = { }
@@ -1,3 +1,4 @@
1
+
1
2
  module Ox
2
3
 
3
4
  # An Element represents a element of an XML document. It has a name,
@@ -32,12 +33,11 @@ module Ox
32
33
  # => "Makie"
33
34
  # doc.People.Person.age
34
35
  # => "58"
35
-
36
36
  class Element < Node
37
37
  include HasAttrs
38
38
 
39
39
  # Creates a new Element with the specified name.
40
- # @param [String] name name of the Element
40
+ # - +name+ [String] name of the Element
41
41
  def initialize(name)
42
42
  super
43
43
  @attributes = {}
@@ -47,7 +47,7 @@ module Ox
47
47
 
48
48
  # Returns the Element's nodes array. These are the sub-elements of this
49
49
  # Element.
50
- # @return [Array] all child Nodes.
50
+ # *return* [Array] all child Nodes.
51
51
  def nodes
52
52
  @nodes = [] if !instance_variable_defined?(:@nodes) or @nodes.nil?
53
53
  @nodes
@@ -55,7 +55,7 @@ module Ox
55
55
 
56
56
  # Appends a Node to the Element's nodes array. Returns the element itself
57
57
  # so multiple appends can be chained together.
58
- # @param [Node] node Node to append to the nodes array
58
+ # - +node+ [Node] Node to append to the nodes array
59
59
  def <<(node)
60
60
  raise "argument to << must be a String or Ox::Node." unless node.is_a?(String) or node.is_a?(Node)
61
61
  @nodes = [] if !instance_variable_defined?(:@nodes) or @nodes.nil?
@@ -65,8 +65,8 @@ module Ox
65
65
 
66
66
  # Returns true if this Object and other are of the same type and have the
67
67
  # equivalent value and the equivalent elements otherwise false is returned.
68
- # @param [Object] other Object compare _self_ to.
69
- # @return [Boolean] true if both Objects are equivalent, otherwise false.
68
+ # - +other+ [Object] Object compare _self_ to.
69
+ # *return* [Boolean] true if both Objects are equivalent, otherwise false.
70
70
  def eql?(other)
71
71
  return false if (other.nil? or self.class != other.class)
72
72
  return false unless super(other)
@@ -85,7 +85,7 @@ module Ox
85
85
 
86
86
  # Clears any child nodes of an element and replaces those with a single Text
87
87
  # (String) node. Note the existing nodes array is modified and not replaced.
88
- # @param [String] txt to become the only element of the nodes array
88
+ # - +txt+ [String] to become the only element of the nodes array
89
89
  def replace_text(txt)
90
90
  raise "the argument to replace_text() must be a String" unless txt.is_a?(String)
91
91
  @nodes.clear()
@@ -127,7 +127,7 @@ module Ox
127
127
  # * <code>element.locate("Family/*/@type")</code> returns the type attribute value for decendents of the Family.
128
128
  # * <code>element.locate("Family/^Comment")</code> returns any comments that are a child of Family.
129
129
  #
130
- # @param [String] path path to the Nodes to locate
130
+ # - +path+ [String] path to the Nodes to locate
131
131
  def locate(path)
132
132
  return [self] if path.nil?
133
133
  found = []
@@ -138,9 +138,10 @@ module Ox
138
138
 
139
139
  # Handles the 'easy' API that allows navigating a simple XML by
140
140
  # referencing elements and attributes by name.
141
- # @param [Symbol] id element or attribute name
142
- # @return [Element|Node|String|nil] the element, attribute value, or Node identifed by the name
143
- # @raise [NoMethodError] if no match is found
141
+ # - +id+ [Symbol] element or attribute name
142
+ # *return* [Element|Node|String|nil] the element, attribute value, or Node identifed by the name
143
+ #
144
+ # _raise_ [NoMethodError] if no match is found
144
145
  def method_missing(id, *args, &block)
145
146
  has_some = false
146
147
  ids = id.to_s
@@ -160,9 +161,9 @@ module Ox
160
161
  raise NoMethodError.new("#{ids} not found", name)
161
162
  end
162
163
 
163
- # @param [String|Symbol] id identifer of the attribute or method
164
- # @param inc_all [Boolean] ignored
165
- # @return true if the element has a member that matches the provided name.
164
+ # - +id+ [String|Symbol] identifer of the attribute or method
165
+ # - +ignored+ inc_all [Boolean]
166
+ # *return* true if the element has a member that matches the provided name.
166
167
  def respond_to?(id, inc_all=false)
167
168
  return true if super
168
169
  id_str = id.to_s
@@ -178,8 +179,8 @@ module Ox
178
179
  false
179
180
  end
180
181
 
181
- # @param [Array] path array of steps in a path
182
- # @param [Array] found matching nodes
182
+ # - +path+ [Array] array of steps in a path
183
+ # - +found+ [Array] matching nodes
183
184
  def alocate(path, found)
184
185
  step = path[0]
185
186
  if step.start_with?('@') # attribute
@@ -1,6 +1,7 @@
1
1
 
2
2
  module Ox
3
3
 
4
+ # Base error class for Ox errors.
4
5
  class Error < StandardError
5
6
  end # Error
6
7
 
@@ -14,6 +15,7 @@ module Ox
14
15
 
15
16
  # An Exception raised if a path is not valid.
16
17
  class InvalidPath < Error
18
+ # Create a new instance with the +path+ specified.
17
19
  def initialize(path)
18
20
  super("#{path.join('/')} is not a valid location.")
19
21
  end
@@ -6,25 +6,24 @@ module Ox
6
6
  #
7
7
  # To access the attributes there are several options. One is to walk the attributes. The easiest for simple regularly
8
8
  # formatted XML is to reference the attributes simply by name.
9
-
10
9
  module HasAttrs
11
10
  # Returns all the attributes of the Instruct as a Hash.
12
- # @return [Hash] all attributes and attribute values.
11
+ # *return* [Hash] all attributes and attribute values.
13
12
  def attributes
14
13
  @attributes = { } if !instance_variable_defined?(:@attributes) or @attributes.nil?
15
14
  @attributes
16
15
  end
17
16
 
18
17
  # Returns the value of an attribute.
19
- # @param [Symbol|String] attr attribute name or key to return the value for
18
+ # - +attr+ [Symbol|String] attribute name or key to return the value for
20
19
  def [](attr)
21
20
  return nil unless instance_variable_defined?(:@attributes) and @attributes.is_a?(Hash)
22
21
  @attributes[attr] or (attr.is_a?(String) ? @attributes[attr.to_sym] : @attributes[attr.to_s])
23
22
  end
24
23
 
25
24
  # Adds or set an attribute of the Instruct.
26
- # @param [Symbol|String] attr attribute name or key
27
- # @param [Object] value value for the attribute
25
+ # - +attr+ [Symbol|String] attribute name or key
26
+ # - +value+ [Object] value for the attribute
28
27
  def []=(attr, value)
29
28
  raise "argument to [] must be a Symbol or a String." unless attr.is_a?(Symbol) or attr.is_a?(String)
30
29
  @attributes = { } if !instance_variable_defined?(:@attributes) or @attributes.nil?
@@ -33,9 +32,9 @@ module Ox
33
32
 
34
33
  # Handles the 'easy' API that allows navigating a simple XML by
35
34
  # referencing attributes by name.
36
- # @param [Symbol] id element or attribute name
37
- # @return [String|nil] the attribute value
38
- # @raise [NoMethodError] if no match is found
35
+ # - +id+ [Symbol] element or attribute name
36
+ # *return* [String|nil] the attribute value
37
+ # _raise_ [NoMethodError] if no match is found
39
38
  def method_missing(id, *args, &block)
40
39
  ids = id.to_s
41
40
  if instance_variable_defined?(:@attributes)
@@ -5,7 +5,6 @@ module Ox
5
5
  # content. The content will be all characters with the exception of the target. If the content follows a regular
6
6
  # attribute format then the attributes will be set to the parsed values. If it does not follow the attribute formate
7
7
  # then the attributes will be empty.
8
-
9
8
  class Instruct < Node
10
9
  include HasAttrs
11
10
 
@@ -13,7 +12,7 @@ module Ox
13
12
  attr_accessor :content
14
13
 
15
14
  # Creates a new Instruct with the specified name.
16
- # @param [String] name name of the Instruct
15
+ # - +name+ [String] name of the Instruct
17
16
  def initialize(name)
18
17
  super
19
18
  @attributes = nil
@@ -23,8 +22,8 @@ module Ox
23
22
 
24
23
  # Returns true if this Object and other are of the same type and have the
25
24
  # equivalent value and the equivalent elements otherwise false is returned.
26
- # @param [Object] other Object compare _self_ to.
27
- # @return [Boolean] true if both Objects are equivalent, otherwise false.
25
+ # - +other+ [Object] Object compare _self_ to.
26
+ # *return* [Boolean] true if both Objects are equivalent, otherwise false.
28
27
  def eql?(other)
29
28
  return false if (other.nil? or self.class != other.class)
30
29
  return false unless super(other)
@@ -6,14 +6,14 @@ module Ox
6
6
  attr_accessor :value
7
7
 
8
8
  # Creates a new Node with the specified String value.
9
- # @param [String] value string value for the Node
9
+ # - +value+ [String] string value for the Node
10
10
  def initialize(value)
11
11
  @value = value.to_s
12
12
  end
13
13
 
14
14
  # Returns true if this Object and other are of the same type and have the
15
15
  # equivalent value otherwise false is returned.
16
- # @param [Object] other Object to compare _self_ to.
16
+ # - +other+ [Object] Object to compare _self_ to.
17
17
  def eql?(other)
18
18
  return false if (other.nil? or self.class != other.class)
19
19
  other.value == self.value
@@ -5,7 +5,7 @@ module Ox
5
5
  # injected as-is.
6
6
  class Raw < Node
7
7
  # Creates a new Raw element with the specified value.
8
- # @param value [String] string value for the comment
8
+ # - +value+ [String] string value for the comment
9
9
  def initialize(value)
10
10
  super
11
11
  end
@@ -1,9 +1,11 @@
1
+
1
2
  module Ox
2
3
  # A SAX style parse handler. The Ox::Sax handler class should be subclasses
3
4
  # and then used with the Ox.sax_parse() method. The Sax methods will then be
4
5
  # called as the file is parsed. This is best suited for very large files or
5
6
  # IO streams.<p/>
6
- # @example
7
+ #
8
+ # *Example*
7
9
  #
8
10
  # require 'ox'
9
11
  #
@@ -45,11 +47,11 @@ module Ox
45
47
  # def start_element(name); end
46
48
  # def end_element(name); end
47
49
  #
48
- # Initializing @line in the initializer will cause that variable to be updated
49
- # before each callback with the XML line number. The same is true for the
50
- # @column but it will be updated with the column in the XML file that is the
51
- # start of the element or node just read. @pos if defined will hold the number
52
- # of bytes from the start of the document.
50
+ # Initializing _line_ attribute in the initializer will cause that variable to
51
+ # be updated before each callback with the XML line number. The same is true
52
+ # for the _column_ attribute but it will be updated with the column in the XML
53
+ # file that is the start of the element or node just read. @pos if defined
54
+ # will hold the number of bytes from the start of the document.
53
55
  class Sax
54
56
  # Create a new instance of the Sax handler class.
55
57
  def initialize()
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '2.3.0'
4
+ VERSION = '2.4.0'
5
5
  end
@@ -11,12 +11,13 @@ module Ox
11
11
  # require 'ox/xmlrpc_adapter'
12
12
  # client = XMLRPC::Client.new2('http://some_server/rpc')
13
13
  # client.set_parser(Ox::StreamParser.new)
14
- #
15
14
  class StreamParser < XMLRPC::XMLParser::AbstractStreamParser
15
+ # Create a new instance.
16
16
  def initialize
17
17
  @parser_class = OxParser
18
18
  end
19
19
 
20
+ # The SAX wrapper.
20
21
  class OxParser < Ox::Sax
21
22
  include XMLRPC::XMLParser::StreamParserMixin
22
23
 
@@ -24,6 +25,7 @@ module Ox
24
25
  alias :end_element :endElement
25
26
  alias :start_element :startElement
26
27
 
28
+ # Initiates the sax parser with the provided string.
27
29
  def parse(str)
28
30
  Ox.sax_parse(self, StringIO.new(str), :symbolize => false, :convert_special => true)
29
31
  end
metadata CHANGED
@@ -1,19 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Peter Ohler
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-02-21 00:00:00.000000000 Z
12
+ date: 2016-04-14 00:00:00.000000000 Z
12
13
  dependencies: []
13
- description: "A fast XML parser and object serializer that uses only standard C lib.\n
14
- \ \nOptimized XML (Ox), as the name implies was written to provide speed
15
- optimized\nXML handling. It was designed to be an alternative to Nokogiri and other
16
- Ruby\nXML parsers for generic XML parsing and as an alternative to Marshal for Object\nserialization. "
14
+ description: ! "A fast XML parser and object serializer that uses only standard C
15
+ lib.\n \nOptimized XML (Ox), as the name implies was written to provide
16
+ speed optimized\nXML handling. It was designed to be an alternative to Nokogiri
17
+ and other Ruby\nXML parsers for generic XML parsing and as an alternative to Marshal
18
+ for Object\nserialization. "
17
19
  email: peter@ohler.com
18
20
  executables: []
19
21
  extensions:
@@ -21,81 +23,84 @@ extensions:
21
23
  extra_rdoc_files:
22
24
  - README.md
23
25
  files:
24
- - LICENSE
25
- - README.md
26
+ - lib/ox/bag.rb
27
+ - lib/ox/cdata.rb
28
+ - lib/ox/comment.rb
29
+ - lib/ox/doctype.rb
30
+ - lib/ox/document.rb
31
+ - lib/ox/element.rb
32
+ - lib/ox/error.rb
33
+ - lib/ox/hasattrs.rb
34
+ - lib/ox/instruct.rb
35
+ - lib/ox/node.rb
36
+ - lib/ox/raw.rb
37
+ - lib/ox/sax.rb
38
+ - lib/ox/version.rb
39
+ - lib/ox/xmlrpc_adapter.rb
40
+ - lib/ox.rb
41
+ - ext/ox/extconf.rb
26
42
  - ext/ox/attr.h
27
- - ext/ox/base64.c
28
43
  - ext/ox/base64.h
29
- - ext/ox/cache.c
44
+ - ext/ox/buf.h
30
45
  - ext/ox/cache.h
31
- - ext/ox/cache8.c
32
46
  - ext/ox/cache8.h
33
- - ext/ox/cache8_test.c
34
- - ext/ox/cache_test.c
47
+ - ext/ox/err.h
48
+ - ext/ox/helper.h
49
+ - ext/ox/ox.h
50
+ - ext/ox/sax.h
51
+ - ext/ox/sax_buf.h
52
+ - ext/ox/sax_has.h
53
+ - ext/ox/sax_hint.h
54
+ - ext/ox/sax_stack.h
55
+ - ext/ox/special.h
56
+ - ext/ox/type.h
57
+ - ext/ox/base64.c
58
+ - ext/ox/builder.c
59
+ - ext/ox/cache.c
60
+ - ext/ox/cache8.c
35
61
  - ext/ox/dump.c
36
- - ext/ox/encode.h
37
62
  - ext/ox/err.c
38
- - ext/ox/err.h
39
- - ext/ox/extconf.rb
40
63
  - ext/ox/gen_load.c
41
- - ext/ox/helper.h
42
64
  - ext/ox/obj_load.c
43
65
  - ext/ox/ox.c
44
- - ext/ox/ox.h
45
66
  - ext/ox/parse.c
46
67
  - ext/ox/sax.c
47
- - ext/ox/sax.h
48
68
  - ext/ox/sax_as.c
49
69
  - ext/ox/sax_buf.c
50
- - ext/ox/sax_buf.h
51
- - ext/ox/sax_has.h
52
70
  - ext/ox/sax_hint.c
53
- - ext/ox/sax_hint.h
54
- - ext/ox/sax_stack.h
55
71
  - ext/ox/special.c
56
- - ext/ox/special.h
57
- - ext/ox/type.h
58
- - lib/ox.rb
59
- - lib/ox/bag.rb
60
- - lib/ox/cdata.rb
61
- - lib/ox/comment.rb
62
- - lib/ox/doctype.rb
63
- - lib/ox/document.rb
64
- - lib/ox/element.rb
65
- - lib/ox/error.rb
66
- - lib/ox/hasattrs.rb
67
- - lib/ox/instruct.rb
68
- - lib/ox/node.rb
69
- - lib/ox/raw.rb
70
- - lib/ox/sax.rb
71
- - lib/ox/version.rb
72
- - lib/ox/xmlrpc_adapter.rb
72
+ - LICENSE
73
+ - README.md
73
74
  homepage: http://www.ohler.com/ox
74
75
  licenses:
75
76
  - MIT
76
- metadata: {}
77
77
  post_install_message:
78
78
  rdoc_options:
79
- - "--main"
79
+ - --main
80
80
  - README.md
81
+ - --title
82
+ - Ox Documentation
83
+ - --exclude
84
+ - extconf.rb
81
85
  require_paths:
82
86
  - lib
83
87
  - ext
84
88
  required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
85
90
  requirements:
86
- - - ">="
91
+ - - ! '>='
87
92
  - !ruby/object:Gem::Version
88
93
  version: '0'
89
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
90
96
  requirements:
91
- - - ">="
97
+ - - ! '>='
92
98
  - !ruby/object:Gem::Version
93
99
  version: '0'
94
100
  requirements: []
95
101
  rubyforge_project: ox
96
- rubygems_version: 2.4.5
102
+ rubygems_version: 1.8.23.2
97
103
  signing_key:
98
- specification_version: 4
104
+ specification_version: 3
99
105
  summary: A fast XML parser and object serializer.
100
106
  test_files: []
101
- has_rdoc: true