Class: Saxon::ParserFeatures

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/saxon/parse_options.rb

Overview

Provides idiomatic access to parser properties

Instance Method Summary collapse

Constructor Details

#initialize(parse_options) ⇒ ParserFeatures

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.

Returns a new instance of ParserFeatures.

Parameters:



88
89
90
# File 'lib/saxon/parse_options.rb', line 88

def initialize(parse_options)
  @parse_options ||= parse_options
end

Instance Method Details

#[](uri) ⇒ Boolean?

Fetch the current value of a Parser Feature

Parameters:

  • uri (String, URI)

    The Parser Feature URI to fetch

Returns:

  • (Boolean, nil)

    The current value of the feature, or nil if it’s unset



102
103
104
105
106
# File 'lib/saxon/parse_options.rb', line 102

def [](uri)
  pf = parse_options.getParserFeatures
  return nil if pf.nil? || !pf.include?(uri)
  parse_options.getParserFeature(uri)
end

#[]=(uri, value) ⇒ Boolean

Set the value of a Parser Feature

Parameters:

  • uri (String, URI)

    The Parser Property URI to set

  • value (Boolean)

    The value to set the property to

Returns:

  • (Boolean)

    The new value of the property



113
114
115
116
# File 'lib/saxon/parse_options.rb', line 113

def []=(uri, value)
  parse_options.addParserFeature(uri, value)
  self[uri]
end

#each {|uri, value| ... } ⇒ Object

Iterate across each currently-set feature, in the same way as a hash

Yields:

  • (uri, value)

Yield Parameters:

  • uri (String)

    The URI of the feature as a String

  • value (Boolean)

    Whether the feature is on or off



123
124
125
# File 'lib/saxon/parse_options.rb', line 123

def each(&block)
  to_h.each(&block)
end

#to_hHash

Returns the currently-set features as a (frozen) hash.

Returns:

  • (Hash)

    the currently-set features as a (frozen) hash



93
94
95
# File 'lib/saxon/parse_options.rb', line 93

def to_h
  (parse_options.getParserFeatures || {}).freeze
end