Class RSS::XMLStyleSheet
In: lib/rss/xml-stylesheet.rb
Parent: Object

Methods

alternate=   guess_type   href=   new   setup_maker   to_s  

Included Modules

Utils

Constants

ATTRIBUTES = %w(href type title media charset alternate)
GUESS_TABLE = { "xsl" => "text/xsl", "css" => "text/css", }

Attributes

do_validate  [RW] 

Public Class methods

[Source]

    # File lib/rss/xml-stylesheet.rb, line 37
37:     def initialize(*attrs)
38:       @do_validate = true
39:       ATTRIBUTES.each do |attr|
40:         __send__("#{attr}=", nil)
41:       end
42:       vars = ATTRIBUTES.dup
43:       vars.unshift(:do_validate)
44:       attrs.each do |name, value|
45:         if vars.include?(name.to_s)
46:           __send__("#{name}=", value)
47:         end
48:       end
49:     end

Public Instance methods

[Source]

    # File lib/rss/xml-stylesheet.rb, line 75
75:     def alternate=(value)
76:       if value.nil? or /\A(?:yes|no)\z/ =~ value
77:         @alternate = value
78:       else
79:         if @do_validate
80:           args = ["?xml-stylesheet?", %Q[alternate="#{value}"]]
81:           raise NotAvailableValueError.new(*args)
82:         end
83:       end
84:       @alternate
85:     end

[Source]

    # File lib/rss/xml-stylesheet.rb, line 66
66:     def href=(value)
67:       @href = value
68:       if @href and @type.nil?
69:         @type = guess_type(@href)
70:       end
71:       @href
72:     end

[Source]

    # File lib/rss/xml-stylesheet.rb, line 87
87:     def setup_maker(maker)
88:       xss = maker.xml_stylesheets.new_xml_stylesheet
89:       ATTRIBUTES.each do |attr|
90:         xss.__send__("#{attr}=", __send__(attr))
91:       end
92:     end

[Source]

    # File lib/rss/xml-stylesheet.rb, line 51
51:     def to_s
52:       rv = ""
53:       if @href
54:         rv << %Q[<?xml-stylesheet]
55:         ATTRIBUTES.each do |name|
56:           if __send__(name)
57:             rv << %Q[ #{name}="#{h __send__(name)}"]
58:           end
59:         end
60:         rv << %Q[?>]
61:       end
62:       rv
63:     end

Private Instance methods

[Source]

    # File lib/rss/xml-stylesheet.rb, line 95
95:     def guess_type(filename)
96:       /\.([^.]+)$/ =~ filename
97:       GUESS_TABLE[$1]
98:     end

[Validate]