Class: Moxml::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/moxml/config.rb

Constant Summary collapse

VALID_ADAPTERS =
%i[nokogiri oga ox].freeze
DEFAULT_ADAPTER =
VALID_ADAPTERS.first

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter_name = nil, strict_parsing = nil, default_encoding = nil) ⇒ Config

Returns a new instance of Config.



20
21
22
23
24
25
26
27
# File 'lib/moxml/config.rb', line 20

def initialize(adapter_name = nil, strict_parsing = nil, default_encoding = nil)
  self.adapter = adapter_name || Config.default.adapter_name
  @strict_parsing = strict_parsing || Config.default.strict_parsing
  @default_encoding = default_encoding || Config.default.default_encoding
  # reserved for future use
  @default_indent = 2
  @entity_encoding = :basic
end

Instance Attribute Details

#adapter_nameObject (readonly)

Returns the value of attribute adapter_name.



14
15
16
# File 'lib/moxml/config.rb', line 14

def adapter_name
  @adapter_name
end

#default_encodingObject

Returns the value of attribute default_encoding.



15
16
17
# File 'lib/moxml/config.rb', line 15

def default_encoding
  @default_encoding
end

#default_indentObject

Returns the value of attribute default_indent.



15
16
17
# File 'lib/moxml/config.rb', line 15

def default_indent
  @default_indent
end

#entity_encodingObject

Returns the value of attribute entity_encoding.



15
16
17
# File 'lib/moxml/config.rb', line 15

def entity_encoding
  @entity_encoding
end

#strict_parsingObject

Returns the value of attribute strict_parsing.



15
16
17
# File 'lib/moxml/config.rb', line 15

def strict_parsing
  @strict_parsing
end

Class Method Details

.defaultObject



9
10
11
# File 'lib/moxml/config.rb', line 9

def default
  @default ||= new(DEFAULT_ADAPTER, true, "UTF-8")
end

Instance Method Details

#adapterObject



43
44
45
# File 'lib/moxml/config.rb', line 43

def adapter
  @adapter ||= Adapter.load(@adapter_name)
end

#adapter=(name) ⇒ Object Also known as: default_adapter=



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/moxml/config.rb', line 29

def adapter=(name)
  name = name.to_sym
  @adapter = nil

  unless VALID_ADAPTERS.include?(name)
    raise ArgumentError, "Invalid adapter: #{name}. Valid adapters are: #{VALID_ADAPTERS.join(", ")}"
  end

  @adapter_name = name
  adapter
end