Object
# File rss/rss.rb, line 808 def add_have_children_element(variable_name, plural_name) self::HAVE_CHILDREN_ELEMENTS << [variable_name, plural_name] end
# File rss/rss.rb, line 816 def add_need_initialize_variable(variable_name) self::NEED_INITIALIZE_VARIABLES << variable_name end
# File rss/rss.rb, line 820 def add_plural_form(singular, plural) self::PLURAL_FORMS[singular] = plural end
# File rss/rss.rb, line 812 def add_to_element_method(method_name) self::TO_ELEMENT_METHODS << method_name end
# File rss/rss.rb, line 797 def content_setup(type=nil, disp_name=nil) writer_type, reader_type = type def_corresponded_attr_writer :content, writer_type, disp_name def_corresponded_attr_reader :content, reader_type @have_content = true end
# File rss/rss.rb, line 778 def def_corresponded_attr_reader(name, type=nil) case type when :inherit inherit_convert_attr_reader name when :uri uri_convert_attr_reader name when :explicit_clean_other explicit_clean_other_attr_reader name when :yes_other yes_other_attr_reader name when :csv csv_attr_reader name when :csv_integer csv_attr_reader name, :separator => "," else convert_attr_reader name end end
# File rss/rss.rb, line 750 def def_corresponded_attr_writer(name, type=nil, disp_name=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 when :text_type text_type_writer name, disp_name when :content content_writer name, disp_name when :explicit_clean_other explicit_clean_other_writer name, disp_name when :yes_other yes_other_writer name, disp_name when :csv csv_writer name when :csv_integer csv_integer_writer name else attr_writer name end end
# File rss/rss.rb, line 687 def get_attributes inherited_array_reader("GET_ATTRIBUTES") end
# File rss/rss.rb, line 690 def have_children_elements inherited_array_reader("HAVE_CHILDREN_ELEMENTS") end
# File rss/rss.rb, line 804 def have_content? @have_content end
# File rss/rss.rb, line 707 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, {}) tag_name = klass.name.split(/::/).last tag_name[0, 1] = tag_name[0, 1].downcase klass.instance_variable_set(:@tag_name, tag_name) klass.instance_variable_set(:@have_content, false) end
# File rss/rss.rb, line 703 def inherited_base ::RSS::Element end
# File rss/rss.rb, line 735 def install_get_attribute(name, uri, required=true, type=nil, disp_name=nil, element_name=nil) disp_name ||= name element_name ||= name writer_type, reader_type = type def_corresponded_attr_writer name, writer_type, disp_name def_corresponded_attr_reader name, reader_type if type == :boolean and /^is/ =~ name alias_method "#{$POSTMATCH}?", name end self::GET_ATTRIBUTES << [name, uri, required, element_name] add_need_initialize_variable(disp_name) end
# File rss/rss.rb, line 726 def install_model(tag, uri, occurs=nil, getter=nil, plural=false) getter ||= tag if m = self::MODELS.find {|t, u, o, g, p| t == tag and u == uri} m[2] = occurs else self::MODELS << [tag, uri, occurs, getter, plural] end end
# File rss/rss.rb, line 722 def install_must_call_validator(prefix, uri) self::MUST_CALL_VALIDATORS[uri] = prefix end
# File rss/rss.rb, line 836 def install_ns(prefix, uri) if self::NSPOOL.has_key?(prefix) raise OverlappedPrefixError.new(prefix) end self::NSPOOL[prefix] = uri end
# File rss/rss.rb, line 684 def models inherited_array_reader("MODELS") end
# File rss/rss.rb, line 681 def must_call_validators inherited_hash_reader("MUST_CALL_VALIDATORS") end
# File rss/rss.rb, line 696 def need_initialize_variables inherited_array_reader("NEED_INITIALIZE_VARIABLES") end
# File rss/rss.rb, line 850 def initialize(do_validate=true, attrs=nil) @parent = nil @converter = nil if attrs.nil? and (do_validate.is_a?(Hash) or do_validate.is_a?(Array)) do_validate, attrs = true, do_validate end @do_validate = do_validate initialize_variables(attrs || {}) end
# File rss/rss.rb, line 879 def convert(value) if @converter @converter.convert(value) else value end end
# File rss/rss.rb, line 868 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
# File rss/rss.rb, line 929 def have_xml_content? false end
# File rss/rss.rb, line 933 def need_base64_encode? false end
# File rss/rss.rb, line 937 def set_next_element(tag_name, next_element) klass = next_element.class prefix = "" prefix << "#{klass.required_prefix}_" if klass.required_prefix key = "#{prefix}#{tag_name.gsub(/-/, '_')}" if self.class.plural_forms.has_key?(key) ary = __send__("#{self.class.plural_forms[key]}") ary << next_element else __send__("#{key}=", next_element) end end
# File rss/rss.rb, line 908 def to_s(need_convert=true, indent='') if self.class.have_content? return "" if !empty_content? and !content_is_set? rv = tag(indent) do |next_indent| if empty_content? "" else xmled_content end 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
# File rss/rss.rb, line 887 def valid?(ignore_unknown_element=true) validate(ignore_unknown_element) true rescue RSS::Error false end
# File rss/rss.rb, line 951 def have_required_elements? self.class::MODELS.all? do |tag, uri, occurs, getter| if occurs.nil? or occurs == "+" child = __send__(getter) if child.is_a?(Array) children = child children.any? {|c| c.have_required_elements?} else not child.nil? end else true end end end