Class: Resync::XML::MimeTypeNode

Inherits:
XML::Mapping::SingleAttributeNode
  • Object
show all
Defined in:
lib/resync/xml.rb

Overview

Maps MIME::Type values.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MimeTypeNode

Returns a new instance of MimeTypeNode.



161
162
163
164
165
# File 'lib/resync/xml.rb', line 161

def initialize(*args)
  path, *args = super(*args)
  @path = ::XML::XXPath.new(path)
  args
end

Instance Method Details

#extract_attr_value(xml) ⇒ Object

Implements ::XML::Mapping::SingleAttributeNode#extract_attr_value.



168
169
170
171
172
173
174
175
176
177
# File 'lib/resync/xml.rb', line 168

def extract_attr_value(xml)
  mime_type = default_when_xpath_err { @path.first(xml).text }
  return nil unless mime_type
  return mime_type if mime_type.is_a?(MIME::Type)

  mt = MIME::Types[mime_type].first
  return mt if mt

  MIME::Type.new(mime_type)
end

#set_attr_value(xml, value) ⇒ Object

Implements ::XML::Mapping::SingleAttributeNode#set_attr_value.



180
181
182
# File 'lib/resync/xml.rb', line 180

def set_attr_value(xml, value)
  @path.first(xml, ensure_created: true).text = value.to_s
end