Class: RSS::Atom::Feed::Entry::Content

Inherits:
Element
  • Object
show all
Includes:
CommonModel
Defined in:
lib/rss/atom.rb

Constant Summary

Constants included from CommonModel

CommonModel::ELEMENTS, CommonModel::NSPOOL

Constants inherited from Element

Element::GET_ATTRIBUTES, Element::HAVE_CHILDREN_ELEMENTS, Element::INDENT, Element::MODELS, Element::MUST_CALL_VALIDATORS, Element::NEED_INITIALIZE_VARIABLES, Element::PLURAL_FORMS, Element::TO_ELEMENT_METHODS

Instance Attribute Summary collapse

Attributes inherited from Element

#do_validate, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommonModel

append_features

Methods inherited from Element

add_have_children_element, add_need_initialize_variable, add_plural_form, add_to_element_method, content_setup, #convert, #converter=, def_corresponded_attr_reader, def_corresponded_attr_writer, #full_name, get_attributes, have_children_elements, have_content?, inherited, inherited_base, #initialize, install_get_attribute, install_model, install_must_call_validator, install_ns, models, must_call_validators, need_initialize_variables, need_parent?, plural_forms, required_prefix, required_uri, #set_next_element, tag_name, #tag_name, to_element_methods, #to_s, #valid?, #validate, #validate_for_stream

Methods included from Utils::InheritedReader

#inherited_array_reader, #inherited_hash_reader, #inherited_reader

Methods included from BaseModel

#install_date_element, #install_have_child_element, #install_have_children_element, #install_text_element

Methods included from Utils

element_initialize_arguments?, get_file_and_line_from_caller, html_escape, new_with_value_if_need, to_class_name

Methods included from SetupMaker

#setup_maker

Constructor Details

This class inherits a constructor from RSS::Element

Instance Attribute Details

#xmlObject



476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/rss/atom.rb', line 476

def xml
  return @xml unless inline_xhtml?
  return @xml if @xml.nil?
  if @xml.is_a?(XML::Element) and
      [@xml.name, @xml.uri] == ["div", XHTML_URI]
    return @xml
  end

  children = @xml
  children = [children] unless children.is_a?(Array)
  XML::Element.new("div", nil, XHTML_URI,
                   {"xmlns" => XHTML_URI}, children)
end

Class Method Details

.xml_getterObject



456
457
458
# File 'lib/rss/atom.rb', line 456

def xml_getter
  "xml"
end

.xml_setterObject



452
453
454
# File 'lib/rss/atom.rb', line 452

def xml_setter
  "xml="
end

Instance Method Details

#atom_validate(ignore_unknown_element, tags, uri) ⇒ Object



498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/rss/atom.rb', line 498

def atom_validate(ignore_unknown_element, tags, uri)
  if out_of_line?
    raise MissingAttributeError.new(tag_name, "type") if @type.nil?
    unless (content.nil? or content.empty?)
      raise NotAvailableValueError.new(tag_name, content)
    end
  elsif inline_xhtml?
    if @xml.nil?
      raise MissingTagError.new("div", tag_name)
    end
    unless @xml.name == "div" and @xml.uri == XHTML_URI
      raise NotExpectedTagError.new(@xml.name, @xml.uri, tag_name)
    end
  end
end

#have_xml_content?Boolean

Returns:

  • (Boolean)


472
473
474
# File 'lib/rss/atom.rb', line 472

def have_xml_content?
  inline_xhtml? or inline_other_xml?
end

#inline_html?Boolean

Returns:

  • (Boolean)


518
519
520
521
# File 'lib/rss/atom.rb', line 518

def inline_html?
  return false if out_of_line?
  @type == "html" or mime_split == ["text", "html"]
end

#inline_other?Boolean

Returns:

  • (Boolean)


527
528
529
530
531
532
# File 'lib/rss/atom.rb', line 527

def inline_other?
  return false if out_of_line?
  media_type, subtype = mime_split
  return false if media_type.nil? or subtype.nil?
  true
end

#inline_other_base64?Boolean

Returns:

  • (Boolean)


557
558
559
# File 'lib/rss/atom.rb', line 557

def inline_other_base64?
  inline_other? and !inline_other_text? and !inline_other_xml?
end

#inline_other_text?Boolean

Returns:

  • (Boolean)


534
535
536
537
538
539
540
541
# File 'lib/rss/atom.rb', line 534

def inline_other_text?
  return false unless inline_other?
  return false if inline_other_xml?

  media_type, = mime_split
  return true if "text" == media_type.downcase
  false
end

#inline_other_xml?Boolean

Returns:

  • (Boolean)


543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/rss/atom.rb', line 543

def inline_other_xml?
  return false unless inline_other?

  media_type, subtype = mime_split
  normalized_mime_type = "#{media_type}/#{subtype}".downcase
  if /(?:\+xml|^xml)$/ =~ subtype or
      %w(text/xml-external-parsed-entity
         application/xml-external-parsed-entity
         application/xml-dtd).find {|x| x == normalized_mime_type}
    return true
  end
  false
end

#inline_text?Boolean

Returns:

  • (Boolean)


514
515
516
# File 'lib/rss/atom.rb', line 514

def inline_text?
  !out_of_line? and [nil, "text", "html"].include?(@type)
end

#inline_xhtml?Boolean

Returns:

  • (Boolean)


523
524
525
# File 'lib/rss/atom.rb', line 523

def inline_xhtml?
  !out_of_line? and @type == "xhtml"
end

#mime_splitObject



565
566
567
568
569
570
571
572
# File 'lib/rss/atom.rb', line 565

def mime_split
  media_type = subtype = nil
  if /\A\s*([a-z]+)\/([a-z\+]+)\s*(?:;.*)?\z/i =~ @type.to_s
    media_type = $1.downcase
    subtype = $2.downcase
  end
  [media_type, subtype]
end

#need_base64_encode?Boolean

Returns:

  • (Boolean)


574
575
576
# File 'lib/rss/atom.rb', line 574

def need_base64_encode?
  inline_other_base64?
end

#out_of_line?Boolean

Returns:

  • (Boolean)


561
562
563
# File 'lib/rss/atom.rb', line 561

def out_of_line?
  not @src.nil?
end

#xhtmlObject



490
491
492
493
494
495
496
# File 'lib/rss/atom.rb', line 490

def xhtml
  if inline_xhtml?
    xml
  else
    nil
  end
end