Class: Leptris::XML::ParseOptions

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#flagsObject (readonly)

Returns the value of attribute flags.



12
13
14
# File 'lib/leptris/xml/parse_options.rb', line 12

def flags
  @flags
end

#recoverObject (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

.noblanksObject



27
28
29
# File 'lib/leptris/xml/parse_options.rb', line 27

def self.noblanks
  new(NOBLANKS)
end

.recoveringObject



31
32
33
# File 'lib/leptris/xml/parse_options.rb', line 31

def self.recovering
  new(recover: true)
end

Instance Method Details

#noblanks?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/leptris/xml/parse_options.rb', line 35

def noblanks?
  @flags & NOBLANKS != 0
end

#recover?Boolean

Returns:

  • (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).

Returns:

  • (Boolean)


49
50
51
# File 'lib/leptris/xml/parse_options.rb', line 49

def struct_required?
  recover?
end

#to_c_structObject

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