Class: Leptris::XML::ParseOptions
- Inherits:
-
Object
- Object
- Leptris::XML::ParseOptions
- Defined in:
- lib/leptris/xml/parse_options.rb
Overview
Parser flags, mirroring LeptrisParseFlags in libleptris's public
headers. Pass an instance as Leptris::XML.parse(xml, options:).
Constant Summary collapse
- NOBLANKS =
Discard whitespace-only text nodes (runs between tags that contain nothing but spaces/tabs/newlines). Matches libxml2's XML_PARSE_NOBLANKS and Nokogiri's noblanks. Documents parsed this way do not round-trip pretty-printed formatting byte-for-byte.
Leptris::XML::FFI::LEPTRIS_PARSE_DROP_WS_TEXT
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#recover ⇒ Object
readonly
Recover (libleptris 1.9.0, #547): a parse failure returns an empty document with the failure recorded in Document#last_error instead of raising — the libxml2 XML_PARSE_RECOVER semantics adapters emulate.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(flags = Leptris::XML::FFI::LEPTRIS_PARSE_DEFAULT, recover: false) ⇒ ParseOptions
constructor
A new instance of ParseOptions.
- #noblanks? ⇒ Boolean
- #recover? ⇒ Boolean
-
#struct_required? ⇒ Boolean
True when the options cannot ride the flags-only parse path and need the full LeptrisParseOptions struct (leptris_parse_string_ex).
-
#to_c_struct ⇒ Object
Builds the C LeptrisParseOptions struct mirroring this instance.
- #|(other) ⇒ Object
Constructor Details
#initialize(flags = Leptris::XML::FFI::LEPTRIS_PARSE_DEFAULT, recover: false) ⇒ ParseOptions
Returns a new instance of ParseOptions.
21 22 23 24 25 |
# File 'lib/leptris/xml/parse_options.rb', line 21 def initialize(flags = Leptris::XML::FFI::LEPTRIS_PARSE_DEFAULT, recover: false) @flags = flags.to_i @recover = recover ? true : false end |
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
12 13 14 |
# File 'lib/leptris/xml/parse_options.rb', line 12 def flags @flags end |
#recover ⇒ Object (readonly)
Recover (libleptris 1.9.0, #547): a parse failure returns an empty document with the failure recorded in Document#last_error instead of raising — the libxml2 XML_PARSE_RECOVER semantics adapters emulate. Struct-only (not a parse flag): carrying it routes Document.parse through leptris_parse_string_ex.
19 20 21 |
# File 'lib/leptris/xml/parse_options.rb', line 19 def recover @recover end |
Class Method Details
.noblanks ⇒ Object
27 28 29 |
# File 'lib/leptris/xml/parse_options.rb', line 27 def self.noblanks new(NOBLANKS) end |
.recovering ⇒ Object
31 32 33 |
# File 'lib/leptris/xml/parse_options.rb', line 31 def self.recovering new(recover: true) end |
Instance Method Details
#noblanks? ⇒ Boolean
35 36 37 |
# File 'lib/leptris/xml/parse_options.rb', line 35 def noblanks? @flags & NOBLANKS != 0 end |
#recover? ⇒ Boolean
39 40 41 |
# File 'lib/leptris/xml/parse_options.rb', line 39 def recover? @recover == true end |
#struct_required? ⇒ Boolean
True when the options cannot ride the flags-only parse path and need the full LeptrisParseOptions struct (leptris_parse_string_ex).
49 50 51 |
# File 'lib/leptris/xml/parse_options.rb', line 49 def struct_required? recover? end |
#to_c_struct ⇒ Object
Builds the C LeptrisParseOptions struct mirroring this instance.
54 55 56 57 58 59 60 61 |
# File 'lib/leptris/xml/parse_options.rb', line 54 def to_c_struct struct = Leptris::XML::FFI::ParseOptionsStruct.new struct[:flags] = @flags struct[:strict_mode] = -1 struct[:max_depth] = 0 struct[:recover] = @recover ? 1 : 0 struct end |
#|(other) ⇒ Object
43 44 45 |
# File 'lib/leptris/xml/parse_options.rb', line 43 def |(other) self.class.new(@flags | other.flags, recover: @recover || other.recover?) end |