Skip to content

Commit a729393

Browse files
committed
Add rdoc call-seq comments to Schema and Error classes
1 parent 75b127b commit a729393

4 files changed

Lines changed: 81 additions & 3 deletions

File tree

lib/libxml/error.rb

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Error
2323
map[const_get(code)] = code
2424
end
2525
end
26-
26+
2727
# Verbose error handler
2828
VERBOSE_HANDLER = lambda do |error|
2929
STDERR << error.to_s << "\n"
@@ -33,11 +33,20 @@ class Error
3333
# Quiet error handler
3434
QUIET_HANDLER = lambda do |error|
3535
end
36-
36+
37+
# call-seq:
38+
# error == other -> true or false
39+
#
40+
# Returns whether two errors have the same attributes.
3741
def ==(other)
3842
eql?(other)
3943
end
40-
44+
45+
# call-seq:
46+
# error.eql?(other) -> true or false
47+
#
48+
# Returns whether two errors have identical code, domain, message,
49+
# level, file, line, and all other attributes.
4150
def eql?(other)
4251
self.code == other.code and
4352
self.domain == other.domain and
@@ -56,6 +65,11 @@ def eql?(other)
5665
false
5766
end
5867

68+
# call-seq:
69+
# error.level_to_s -> String
70+
#
71+
# Returns a human-readable string for the error level:
72+
# "Warning:", "Error:", "Fatal error:", or "".
5973
def level_to_s
6074
case self.level
6175
when NONE
@@ -69,14 +83,27 @@ def level_to_s
6983
end
7084
end
7185

86+
# call-seq:
87+
# error.domain_to_s -> String
88+
#
89+
# Returns the name of the error domain (e.g. "PARSER", "XPATH").
7290
def domain_to_s
7391
DOMAIN_CODE_MAP[self.domain].to_s
7492
end
7593

94+
# call-seq:
95+
# error.code_to_s -> String
96+
#
97+
# Returns the name of the error code constant.
7698
def code_to_s
7799
ERROR_CODE_MAP[self.code].to_s
78100
end
79101

102+
# call-seq:
103+
# error.to_s -> String
104+
#
105+
# Returns a formatted error string including the level, message,
106+
# and file/line when available.
80107
def to_s
81108
msg = super
82109
msg = msg ? msg.strip: ''

lib/libxml/schema/attribute.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ class Schema::Attribute
66
REQUIRED = 1
77
OPTIONAL = 2
88

9+
# call-seq:
10+
# attribute.default -> String or nil
11+
#
12+
# Returns the default value for this attribute, or nil if none.
913
def default
1014
node['default']
1115
end
1216

17+
# call-seq:
18+
# attribute.required? -> true or false
19+
#
20+
# Returns whether this attribute is required.
1321
def required?
1422
occurs == REQUIRED
1523
end

lib/libxml/schema/element.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,42 @@
33
module LibXML
44
module XML
55
class Schema::Element
6+
# call-seq:
7+
# element.min_occurs -> Integer
8+
#
9+
# Returns the minimum number of times this element must appear.
610
def min_occurs
711
@min
812
end
913

14+
# call-seq:
15+
# element.max_occurs -> Integer
16+
#
17+
# Returns the maximum number of times this element may appear.
1018
def max_occurs
1119
@max
1220
end
1321

22+
# call-seq:
23+
# element.required? -> true or false
24+
#
25+
# Returns whether this element is required (min_occurs > 0).
1426
def required?
1527
!min_occurs.zero?
1628
end
1729

30+
# call-seq:
31+
# element.array? -> true or false
32+
#
33+
# Returns whether this element can appear more than once (max_occurs > 1).
1834
def array?
1935
max_occurs > 1
2036
end
2137

38+
# call-seq:
39+
# element.elements -> Hash
40+
#
41+
# Returns the child elements of this element's type.
2242
def elements
2343
type.elements
2444
end

lib/libxml/schema/type.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
11
module LibXML
22
module XML
33
class Schema::Type
4+
# call-seq:
5+
# type.kind_name -> String
6+
#
7+
# Returns the name of the constant that matches this type's +kind+ value.
8+
#
9+
# schema.types['shiporderType'].kind_name
10+
# # => :XML_SCHEMA_TYPE_COMPLEX
411
def kind_name
512
Schema::Types.constants.find { |k| Schema::Types.const_get(k) == kind }
613
end
714

15+
# call-seq:
16+
# type.anonymous_subtypes -> Hash
17+
#
18+
# Returns a Hash of child elements whose types are anonymous
19+
# (inline complex types with no global name).
20+
#
21+
# type.anonymous_subtypes
22+
# # => {"shipto" => #<Schema::Element>, "item" => #<Schema::Element>}
823
def anonymous_subtypes
924
elements.select { |_, e| e.type.name.nil? }
1025
end
1126

27+
# call-seq:
28+
# type.anonymous_subtypes_recursively -> Array
29+
#
30+
# Returns a flattened Array of Hashes mapping qualified names to
31+
# anonymous Schema::Type instances, descending into nested types.
32+
#
33+
# type.anonymous_subtypes_recursively
34+
# # => [{"shipto" => #<Schema::Type>}, {"item" => #<Schema::Type>}]
1235
def anonymous_subtypes_recursively(parent=nil)
1336
anonymous_subtypes.map do |element_name, e|
1437
[{[parent, element_name].compact.join('::') => e.type},

0 commit comments

Comments
 (0)