Class: RSS::XMLStyleSheet

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/rss/xml-stylesheet.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

element_initialize_arguments?, get_file_and_line_from_caller, html_escape, new_with_value_if_need, to_class_name

Constructor Details

#initialize(*attrs) ⇒ XMLStyleSheet

Returns a new instance of XMLStyleSheet.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rss/xml-stylesheet.rb', line 37

def initialize(*attrs)
  if attrs.size == 1 and
      (attrs.first.is_a?(Hash) or attrs.first.is_a?(Array))
    attrs = attrs.first
  end
  @do_validate = true
  ATTRIBUTES.each do |attr|
    __send__("#{attr}=", nil)
  end
  vars = ATTRIBUTES.dup
  vars.unshift(:do_validate)
  attrs.each do |name, value|
    if vars.include?(name.to_s)
      __send__("#{name}=", value)
    end
  end
end

Instance Attribute Details

#do_validateObject

Returns the value of attribute do_validate



36
37
38
# File 'lib/rss/xml-stylesheet.rb', line 36

def do_validate
  @do_validate
end

Instance Method Details

#alternate=(value) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rss/xml-stylesheet.rb', line 79

def alternate=(value)
  if value.nil? or /\A(?:yes|no)\z/ =~ value
    @alternate = value
  else
    if @do_validate
      args = ["?xml-stylesheet?", %Q[alternate="#{value}"]]
      raise NotAvailableValueError.new(*args)
    end
  end
  @alternate
end

#href=(value) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/rss/xml-stylesheet.rb', line 70

def href=(value)
  @href = value
  if @href and @type.nil?
    @type = guess_type(@href)
  end
  @href
end

#setup_maker(maker) ⇒ Object



91
92
93
94
95
96
# File 'lib/rss/xml-stylesheet.rb', line 91

def setup_maker(maker)
  xss = maker.xml_stylesheets.new_xml_stylesheet
  ATTRIBUTES.each do |attr|
    xss.__send__("#{attr}=", __send__(attr))
  end
end

#to_sObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rss/xml-stylesheet.rb', line 55

def to_s
  rv = ""
  if @href
    rv << %Q[<?xml-stylesheet]
    ATTRIBUTES.each do |name|
      if __send__(name)
        rv << %Q[ #{name}="#{h __send__(name)}"]
      end
    end
    rv << %Q[?>]
  end
  rv
end