Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Commit

Permalink
various cosmetics to Text. raise ArgumentError if unknown type
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Nov 1, 2008
1 parent 32ebb05 commit be68622
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lib/atom.rb
Expand Up @@ -35,23 +35,24 @@ class Text < String
def initialize(element)
type = element.attribute('type', NAMESPACE)

@mime_type = if type.nil?
'text/plain'
else
case type.value
when 'text': 'text/plain'
when 'html': 'text/html'
when 'xhtml': 'text/xhtml'
else raise "Unknown type: #{type.value}"
@mime_type =
case type ? type.value : nil
when 'text' then 'text/plain'
when 'html' then 'text/html'
when 'xhtml' then 'text/xhtml'
when nil then 'text/plain'
else
raise ArgumentError, "Unknown type: #{type.value}"
end
end

value = case @mime_type
when 'text/plain', 'text/html': element.texts.map {|t| t.value }.join
when 'text/xhtml' :
REXML::XPath.first(element, 'xhtml:div', 'xhtml' => XHTML_NAMESPACE).children.to_s
value =
case @mime_type
when 'text/plain', 'text/html'
element.texts.map(&:value).join
when 'text/xhtml'
# TODO: resolve relative uris
end
REXML::XPath.first(element, 'xhtml:div', 'xhtml' => XHTML_NAMESPACE).children.to_s
end

super value
end
Expand Down

0 comments on commit be68622

Please sign in to comment.