Class: Kiba::Extend::Sources::XmlDir
- Inherits:
-
Object
- Object
- Kiba::Extend::Sources::XmlDir
show all
- Extended by:
- Sourceable
- Includes:
- Enumerable
- Defined in:
- lib/kiba/extend/sources/xml_dir.rb
Overview
XmlDir is a source yielding one Nokogiri::XML::Document per
XML file. It will issue warnings (on stdout) for any source
file that fails to parse as well-formed XML. This behavior
can be suppressed by passing silent_warnings: true to the
constructor. Regardless of whether the warnings are suppressed,
XmlDir will not yield an XMLDocument for malformed XML.
Other things to be aware of: stripping namespaces might make
your life easier for downstream transformations; you can pass
remove_namespaces: true to the constructor for this purpose
(@see #initialize for details and other options).
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Sourceable
is_source?
#default_args, #default_file_options, #labeled_options, #options_key, #path_key, #requires_path?
Constructor Details
#initialize(dirpath:, recursive: false, filesuffixes: [".xml"], silent_warnings: false, parseopts: Kiba::Extend.xmlopts, remove_namespaces: false) ⇒ XmlDir
Returns a new instance of XmlDir.
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/kiba/extend/sources/xml_dir.rb', line 64
def initialize(dirpath:, recursive: false, filesuffixes: [".xml"],
silent_warnings: false, parseopts: Kiba::Extend.xmlopts,
remove_namespaces: false)
@path = File.expand_path(dirpath)
@recursive = recursive
@filesuffixes = filesuffixes
@silent_warnings = silent_warnings
@parseopts = parseopts
@remove_namespaces = remove_namespaces
end
|
Class Method Details
.default_file_options ⇒ Object
24
25
26
|
# File 'lib/kiba/extend/sources/xml_dir.rb', line 24
def default_file_options
Kiba::Extend.xmlopts
end
|
.options_key ⇒ Object
28
29
30
|
# File 'lib/kiba/extend/sources/xml_dir.rb', line 28
def options_key
nil
end
|
.path_key ⇒ Object
32
33
34
|
# File 'lib/kiba/extend/sources/xml_dir.rb', line 32
def path_key
:dirpath
end
|
.requires_path? ⇒ Boolean
36
37
38
|
# File 'lib/kiba/extend/sources/xml_dir.rb', line 36
def requires_path?
true
end
|
Instance Method Details
#each ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/kiba/extend/sources/xml_dir.rb', line 76
def each
file_list.each do |filepath|
doc = parse(filepath)
next unless doc
if doc.errors.any?
warn_invalid(filepath, doc.errors)
next
end
doc.remove_namespaces! if remove_namespaces
yield doc
end
end
|