Class: XML::MappingExtensions::MimeTypeNode

Inherits:
NodeBase
  • Object
show all
Defined in:
lib/xml/mapping_extensions/mime_type_node.rb

Overview

Converts MIME type strings to MIME::Type objects

Instance Method Summary collapse

Methods inherited from NodeBase

#extract_attr_value, #initialize, #set_attr_value, #to_xml_text

Constructor Details

This class inherits a constructor from XML::MappingExtensions::NodeBase

Instance Method Details

#to_value(xml_text) ⇒ MIME::Type

Converts a MIME type string to a MIME::Type object, either the first corresponding value in the MIME::Types registry, or a newly created value.

Parameters:

  • xml_text

    the MIME type string

Returns:

  • (MIME::Type)

    the corresponding MIME::Type



16
17
18
19
20
21
22
# File 'lib/xml/mapping_extensions/mime_type_node.rb', line 16

def to_value(xml_text)
  if (mt = MIME::Types[xml_text].first)
    mt
  else
    MIME::Type.new(xml_text)
  end
end