Module: XMLable::Mixins::DocumentStorage::ClassMethods
- Defined in:
- lib/xmlable/mixins/document_storage.rb
Instance Method Summary collapse
-
#__document_handler ⇒ XMLable::Handlers::Document
private
Get document’s handler.
-
#__nokogiri_export_options ⇒ Nokogiri::XML::ParseOptions
private
Nokogiri’s options for exporting.
-
#__nokogiri_parse_options ⇒ Nokogiri::XML::ParseOptions
private
Nokogiri’s options for parsing.
-
#document(opts = {}) ⇒ Object
Define document params.
-
#from_xml(xml, _opts = {}) ⇒ XMLable::Document
Initialize document from XML.
-
#nokogiri_export(*args) ⇒ Object
Set the Nokogiri’s export params.
-
#nokogiri_parse(*args) ⇒ Object
Set the Nokogiri’s parsing params.
Instance Method Details
#__document_handler ⇒ XMLable::Handlers::Document
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get document’s handler
109 110 111 |
# File 'lib/xmlable/mixins/document_storage.rb', line 109 def __document_handler @__document_handler ||= Handlers::Document.new(self) end |
#__nokogiri_export_options ⇒ Nokogiri::XML::ParseOptions
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Nokogiri’s options for exporting
98 99 100 |
# File 'lib/xmlable/mixins/document_storage.rb', line 98 def @__nokogiri_export_options ||= Options::NokogiriExport.new end |
#__nokogiri_parse_options ⇒ Nokogiri::XML::ParseOptions
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Nokogiri’s options for parsing
87 88 89 |
# File 'lib/xmlable/mixins/document_storage.rb', line 87 def @__nokogiri_parse_options ||= Nokogiri::XML::ParseOptions.new.recover end |
#document(opts = {}) ⇒ Object
Define document params
57 58 59 |
# File 'lib/xmlable/mixins/document_storage.rb', line 57 def document(opts = {}) opt(opts) if opts.size > 0 end |
#from_xml(xml, _opts = {}) ⇒ XMLable::Document
Initialize document from XML
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/xmlable/mixins/document_storage.rb', line 121 def from_xml(xml, _opts = {}) xml = '' unless xml if xml.is_a?(String) doc = Nokogiri::XML(xml) do |config| config. = .to_i end elsif xml.is?(Nokogiri::XML::Document) doc = xml else raise "Don't know how to parse '#{xml.class}'" end __document_handler.from_xml_document(doc) end |
#nokogiri_export(*args) ⇒ Object
Set the Nokogiri’s export params
73 74 75 76 77 78 |
# File 'lib/xmlable/mixins/document_storage.rb', line 73 def nokogiri_export(*args) .tap do |opts| opts.merge!(args.pop) if args.last.is_a?(Hash) args.each { |opt| opts.save_with.send(opt) if opts.save_with.respond_to?(opt) } end end |
#nokogiri_parse(*args) ⇒ Object
Set the Nokogiri’s parsing params
64 65 66 67 68 |
# File 'lib/xmlable/mixins/document_storage.rb', line 64 def nokogiri_parse(*args) args.each do |opt| .send(opt) if .respond_to?(opt) end end |