Class: RSS::Element
- Inherits:
-
Object
show all
- Extended by:
- BaseModel, Utils::InheritedReader
- Includes:
- SetupMaker, Utils
- Defined in:
- lib/rss/rss.rb
Constant Summary
- INDENT =
" "
- MUST_CALL_VALIDATORS =
{}
- MODELS =
[]
- GET_ATTRIBUTES =
[]
- HAVE_CHILDREN_ELEMENTS =
[]
- TO_ELEMENT_METHODS =
[]
- NEED_INITIALIZE_VARIABLES =
[]
- PLURAL_FORMS =
{}
Instance Attribute Summary (collapse)
Class Method Summary
(collapse)
-
+ (Object) add_have_children_element(variable_name, plural_name)
-
+ (Object) add_need_initialize_variable(variable_name)
-
+ (Object) add_plural_form(singular, plural)
-
+ (Object) add_to_element_method(method_name)
-
+ (Object) content_setup(type = nil, disp_name = nil)
-
+ (Object) def_corresponded_attr_reader(name, type = nil)
-
+ (Object) def_corresponded_attr_writer(name, type = nil, disp_name = nil)
-
+ (Object) get_attributes
-
+ (Object) have_children_elements
-
+ (Boolean) have_content?
-
+ (Object) inherited(klass)
-
+ (Object) inherited_base
-
+ (Object) install_get_attribute(name, uri, required = true, type = nil, disp_name = nil, element_name = nil)
-
+ (Object) install_model(tag, uri, occurs = nil, getter = nil, plural = false)
-
+ (Object) install_must_call_validator(prefix, uri)
-
+ (Object) install_ns(prefix, uri)
-
+ (Object) models
-
+ (Object) must_call_validators
-
+ (Object) need_initialize_variables
-
+ (Boolean) need_parent?
-
+ (Object) plural_forms
-
+ (Object) required_prefix
-
+ (Object) required_uri
-
+ (Object) tag_name
-
+ (Object) to_element_methods
Instance Method Summary
(collapse)
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
- (Element) initialize(do_validate = true, attrs = nil)
A new instance of Element
816
817
818
819
820
821
822
823
824
|
# File 'lib/rss/rss.rb', line 816
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
|
Instance Attribute Details
- (Object) do_validate
Returns the value of attribute do_validate
814
815
816
|
# File 'lib/rss/rss.rb', line 814
def do_validate
@do_validate
end
|
Returns the value of attribute parent
814
815
816
|
# File 'lib/rss/rss.rb', line 814
def parent
@parent
end
|
Class Method Details
+ (Object) add_have_children_element(variable_name, plural_name)
774
775
776
|
# File 'lib/rss/rss.rb', line 774
def add_have_children_element(variable_name, plural_name)
self::HAVE_CHILDREN_ELEMENTS << [variable_name, plural_name]
end
|
+ (Object) add_need_initialize_variable(variable_name)
782
783
784
|
# File 'lib/rss/rss.rb', line 782
def add_need_initialize_variable(variable_name)
self::NEED_INITIALIZE_VARIABLES << variable_name
end
|
786
787
788
|
# File 'lib/rss/rss.rb', line 786
def add_plural_form(singular, plural)
self::PLURAL_FORMS[singular] = plural
end
|
+ (Object) add_to_element_method(method_name)
778
779
780
|
# File 'lib/rss/rss.rb', line 778
def add_to_element_method(method_name)
self::TO_ELEMENT_METHODS << method_name
end
|
+ (Object) content_setup(type = nil, disp_name = nil)
763
764
765
766
767
768
|
# File 'lib/rss/rss.rb', line 763
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
|
+ (Object) def_corresponded_attr_reader(name, type = nil)
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
|
# File 'lib/rss/rss.rb', line 744
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 :yes_clean_other
yes_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
|
+ (Object) def_corresponded_attr_writer(name, type = nil, disp_name = nil)
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
|
# File 'lib/rss/rss.rb', line 716
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 :yes_clean_other
yes_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
|
+ (Object) get_attributes
653
654
655
|
# File 'lib/rss/rss.rb', line 653
def get_attributes
inherited_array_reader("GET_ATTRIBUTES")
end
|
+ (Object) have_children_elements
656
657
658
|
# File 'lib/rss/rss.rb', line 656
def have_children_elements
inherited_array_reader("HAVE_CHILDREN_ELEMENTS")
end
|
+ (Boolean) have_content?
770
771
772
|
# File 'lib/rss/rss.rb', line 770
def have_content?
@have_content
end
|
+ (Object) inherited(klass)
673
674
675
676
677
678
679
680
681
682
683
684
685
686
|
# File 'lib/rss/rss.rb', line 673
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
|
+ (Object) inherited_base
669
670
671
|
# File 'lib/rss/rss.rb', line 669
def inherited_base
::RSS::Element
end
|
+ (Object) install_get_attribute(name, uri, required = true, type = nil, disp_name = nil, element_name = nil)
701
702
703
704
705
706
707
708
709
710
711
712
713
714
|
# File 'lib/rss/rss.rb', line 701
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
|
+ (Object) install_model(tag, uri, occurs = nil, getter = nil, plural = false)
692
693
694
695
696
697
698
699
|
# File 'lib/rss/rss.rb', line 692
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
|
+ (Object) install_must_call_validator(prefix, uri)
688
689
690
|
# File 'lib/rss/rss.rb', line 688
def install_must_call_validator(prefix, uri)
self::MUST_CALL_VALIDATORS[uri] = prefix
end
|
+ (Object) install_ns(prefix, uri)
802
803
804
805
806
807
|
# File 'lib/rss/rss.rb', line 802
def install_ns(prefix, uri)
if self::NSPOOL.has_key?(prefix)
raise OverlappedPrefixError.new(prefix)
end
self::NSPOOL[prefix] = uri
end
|
650
651
652
|
# File 'lib/rss/rss.rb', line 650
def models
inherited_array_reader("MODELS")
end
|
+ (Object) must_call_validators
647
648
649
|
# File 'lib/rss/rss.rb', line 647
def must_call_validators
inherited_hash_reader("MUST_CALL_VALIDATORS")
end
|
+ (Object) need_initialize_variables
662
663
664
|
# File 'lib/rss/rss.rb', line 662
def need_initialize_variables
inherited_array_reader("NEED_INITIALIZE_VARIABLES")
end
|
+ (Boolean) need_parent?
798
799
800
|
# File 'lib/rss/rss.rb', line 798
def need_parent?
false
end
|
665
666
667
|
# File 'lib/rss/rss.rb', line 665
def plural_forms
inherited_hash_reader("PLURAL_FORMS")
end
|
+ (Object) required_prefix
790
791
792
|
# File 'lib/rss/rss.rb', line 790
def required_prefix
nil
end
|
+ (Object) required_uri
794
795
796
|
# File 'lib/rss/rss.rb', line 794
def required_uri
""
end
|
+ (Object) tag_name
809
810
811
|
# File 'lib/rss/rss.rb', line 809
def tag_name
@tag_name
end
|
+ (Object) to_element_methods
659
660
661
|
# File 'lib/rss/rss.rb', line 659
def to_element_methods
inherited_array_reader("TO_ELEMENT_METHODS")
end
|
Instance Method Details
- (Object) convert(value)
845
846
847
848
849
850
851
|
# File 'lib/rss/rss.rb', line 845
def convert(value)
if @converter
@converter.convert(value)
else
value
end
end
|
- (Object) converter=(converter)
834
835
836
837
838
839
840
841
842
843
|
# File 'lib/rss/rss.rb', line 834
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
|
- (Object) full_name
830
831
832
|
# File 'lib/rss/rss.rb', line 830
def full_name
tag_name
end
|
- (Boolean) have_xml_content?
895
896
897
|
# File 'lib/rss/rss.rb', line 895
def have_xml_content?
false
end
|
- (Boolean) need_base64_encode?
899
900
901
|
# File 'lib/rss/rss.rb', line 899
def need_base64_encode?
false
end
|
- (Object) set_next_element(tag_name, next_element)
903
904
905
906
907
908
909
910
911
912
913
914
|
# File 'lib/rss/rss.rb', line 903
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
|
- (Object) tag_name
826
827
828
|
# File 'lib/rss/rss.rb', line 826
def tag_name
self.class.tag_name
end
|
- (Object) to_s(need_convert = true, indent = '')
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
|
# File 'lib/rss/rss.rb', line 874
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
|
- (Boolean) valid?(ignore_unknown_element = true)
853
854
855
856
857
858
|
# File 'lib/rss/rss.rb', line 853
def valid?(ignore_unknown_element=true)
validate(ignore_unknown_element)
true
rescue RSS::Error
false
end
|
- (Object) validate(ignore_unknown_element = true)
860
861
862
863
864
865
866
867
|
# File 'lib/rss/rss.rb', line 860
def validate(ignore_unknown_element=true)
do_validate = @do_validate
@do_validate = true
validate_attribute
__validate(ignore_unknown_element)
ensure
@do_validate = do_validate
end
|
- (Object) validate_for_stream(tags, ignore_unknown_element = true)
869
870
871
872
|
# File 'lib/rss/rss.rb', line 869
def validate_for_stream(tags, ignore_unknown_element=true)
validate_attribute
__validate(ignore_unknown_element, tags, false)
end
|