In Files

  • rss/rss.rb

Class/Module Index [+]

Quicksearch

RSS::Element

Attributes

do_validate[RW]

Public Class Methods

new(do_validate=true, attrs={}) click to toggle source
 
               # File rss/rss.rb, line 569
def initialize(do_validate=true, attrs={})
  @converter = nil
  @do_validate = do_validate
  initialize_variables(attrs)
end
            

Public Instance Methods

convert(value) click to toggle source
 
               # File rss/rss.rb, line 594
def convert(value)
  if @converter
    @converter.convert(value)
  else
    value
  end
end
            
converter=(converter) click to toggle source
 
               # File rss/rss.rb, line 583
def converter=(converter)
  @converter = converter
  targets = children.dup
  self.class.have_children_elements.each do |variable_name, plural_name|
    targets.concat(__send__(plural_name))
  end
  targets.each do |target|
    target.converter = converter unless target.nil?
  end
end
            
full_name() click to toggle source
 
               # File rss/rss.rb, line 579
def full_name
  tag_name
end
            
get_attributes() click to toggle source
 
               # File rss/rss.rb, line 420
def get_attributes
  GET_ATTRIBUTES
end
            
have_children_elements() click to toggle source
 
               # File rss/rss.rb, line 423
def have_children_elements
  HAVE_CHILDREN_ELEMENTS
end
            
inherited(klass) click to toggle source
 
               # File rss/rss.rb, line 437
      def inherited(klass)
        klass.const_set("MUST_CALL_VALIDATORS", {})
        klass.const_set("MODELS", [])
        klass.const_set("GET_ATTRIBUTES", [])
        klass.const_set("HAVE_CHILDREN_ELEMENTS", [])
        klass.const_set("TO_ELEMENT_METHODS", [])
        klass.const_set("NEED_INITIALIZE_VARIABLES", [])
        klass.const_set("PLURAL_FORMS", {})

        klass.module_eval("        public
        
        @tag_name = name.split(/::/).last
        @tag_name[0,1] = @tag_name[0,1].downcase
        @have_content = false

        def self.must_call_validators
          super.merge(MUST_CALL_VALIDATORS)
        end
        def self.models
          MODELS + super
        end
        def self.get_attributes
          GET_ATTRIBUTES + super
        end
        def self.have_children_elements
          HAVE_CHILDREN_ELEMENTS + super
        end
        def self.to_element_methods
          TO_ELEMENT_METHODS + super
        end
        def self.need_initialize_variables
          NEED_INITIALIZE_VARIABLES + super
        end
        def self.plural_forms
          super.merge(PLURAL_FORMS)
        end

      
        def self.install_must_call_validator(prefix, uri)
          MUST_CALL_VALIDATORS[uri] = prefix
        end
        
        def self.install_model(tag, uri, occurs=nil, getter=nil)
          getter ||= tag
          if m = MODELS.find {|t, u, o, g| t == tag and u == uri}
            m[2] = occurs
          else
            MODELS << [tag, uri, occurs, getter]
          end
        end

        def self.install_get_attribute(name, uri, required=true,
                                       type=nil, disp_name=nil,
                                       element_name=nil)
          disp_name ||= name
          element_name ||= name
          def_corresponded_attr_writer name, type, disp_name
          convert_attr_reader name
          if type == :boolean and /^is/ =~ name
            alias_method "\#{$POSTMATCH}?", name
          end
          GET_ATTRIBUTES << [name, uri, required, element_name]
          add_need_initialize_variable(disp_name)
        end

        def self.def_corresponded_attr_writer(name, type=nil, disp_name=name)
          case type
          when :integer
            integer_writer name, disp_name
          when :positive_integer
            positive_integer_writer name, disp_name
          when :boolean
            boolean_writer name, disp_name
          when :w3cdtf, :rfc822, :rfc2822
            date_writer name, type, disp_name
          else
            attr_writer name
          end
        end

        def self.content_setup(type=nil)
          def_corresponded_attr_writer "content", type
          convert_attr_reader :content
          @have_content = true
        end

        def self.have_content?
          @have_content
        end

        def self.add_have_children_element(variable_name, plural_name)
          HAVE_CHILDREN_ELEMENTS << [variable_name, plural_name]
        end
        
        def self.add_to_element_method(method_name)
          TO_ELEMENT_METHODS << method_name
        end

        def self.add_need_initialize_variable(variable_name)
          NEED_INITIALIZE_VARIABLES << variable_name
        end
        
        def self.add_plural_form(singular, plural)
          PLURAL_FORMS[singular] = plural
        end
        
")
      end
            
install_ns(prefix, uri) click to toggle source
 
               # File rss/rss.rb, line 555
def install_ns(prefix, uri)
  if self::NSPOOL.has_key?(prefix)
    raise OverlappedPrefixError.new(prefix)
  end
  self::NSPOOL[prefix] = uri
end
            
models() click to toggle source
 
               # File rss/rss.rb, line 417
def models
  MODELS
end
            
must_call_validators() click to toggle source
 
               # File rss/rss.rb, line 414
def must_call_validators
  MUST_CALL_VALIDATORS
end
            
need_initialize_variables() click to toggle source
 
               # File rss/rss.rb, line 429
def need_initialize_variables
  NEED_INITIALIZE_VARIABLES
end
            
plural_forms() click to toggle source
 
               # File rss/rss.rb, line 432
def plural_forms
  PLURAL_FORMS
end
            
required_prefix() click to toggle source
 
               # File rss/rss.rb, line 547
def required_prefix
  nil
end
            
required_uri() click to toggle source
 
               # File rss/rss.rb, line 551
def required_uri
  ""
end
            
setup_maker(maker) click to toggle source
 
               # File rss/rss.rb, line 612
def setup_maker(maker)
  target = maker_target(maker)
  unless target.nil?
    setup_maker_attributes(target)
    setup_maker_element(target)
    setup_maker_elements(target)
  end
end
            
tag_name() click to toggle source
 
               # File rss/rss.rb, line 562
def tag_name
  @tag_name
end
            
to_element_methods() click to toggle source
 
               # File rss/rss.rb, line 426
def to_element_methods
  TO_ELEMENT_METHODS
end
            
to_s(need_convert=true, indent='') click to toggle source
 
               # File rss/rss.rb, line 621
def to_s(need_convert=true, indent='')
  if self.class.have_content?
    return "" unless @content
    rv = tag(indent) do |next_indent|
      h(@content)
    end
  else
    rv = tag(indent) do |next_indent|
      self.class.to_element_methods.collect do |method_name|
        __send__(method_name, false, next_indent)
      end
    end
  end
  rv = convert(rv) if need_convert
  rv
end
            
validate(ignore_unknown_element=true) click to toggle source
 
               # File rss/rss.rb, line 602
def validate(ignore_unknown_element=true)
  validate_attribute
  __validate(ignore_unknown_element)
end
            
validate_for_stream(tags, ignore_unknown_element=true) click to toggle source
 
               # File rss/rss.rb, line 607
def validate_for_stream(tags, ignore_unknown_element=true)
  validate_attribute
  __validate(ignore_unknown_element, tags, false)
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus