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.



158
159
160
161
162
# File 'lib/resync/xml.rb', line 158

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.



165
166
167
168
169
170
171
172
173
174
# File 'lib/resync/xml.rb', line 165

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.



177
178
179
# File 'lib/resync/xml.rb', line 177

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