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.



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

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.



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

def do_validate
  @do_validate
end

Instance Method Details

#alternate=(value) ⇒ Object



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

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



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

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

#setup_maker(maker) ⇒ Object



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

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

#to_sObject



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

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