Class: Html2rss::RssBuilder::Stylesheet

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/rss_builder/stylesheet.rb

Overview

Represents a stylesheet.

Constant Summary collapse

TYPES =

Allowed stylesheet MIME types for RSS processing instructions.

['text/css', 'text/xsl'].to_set.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(href:, type:, media: 'all') ⇒ Stylesheet

Returns a new instance of Stylesheet.

Parameters:

  • href (String)

    stylesheet URL

  • type (String)

    MIME type (‘text/css` or `text/xsl`)

  • media (String) (defaults to: 'all')

    media query hint for the stylesheet

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
52
# File 'lib/html2rss/rss_builder/stylesheet.rb', line 44

def initialize(href:, type:, media: 'all')
  raise ArgumentError, 'stylesheet.href must be a String' unless href.is_a?(String)
  raise ArgumentError, 'stylesheet.type invalid' unless TYPES.include?(type)
  raise ArgumentError, 'stylesheet.media must be a String' unless media.is_a?(String)

  @href = href
  @type = type
  @media = media
end

Instance Attribute Details

#hrefObject (readonly)

Returns the value of attribute href.



53
54
55
# File 'lib/html2rss/rss_builder/stylesheet.rb', line 53

def href
  @href
end

#mediaObject (readonly)

Returns the value of attribute media.



53
54
55
# File 'lib/html2rss/rss_builder/stylesheet.rb', line 53

def media
  @media
end

#typeObject (readonly)

Returns the value of attribute type.



53
54
55
# File 'lib/html2rss/rss_builder/stylesheet.rb', line 53

def type
  @type
end

Class Method Details

.add(maker, stylesheets) ⇒ nil

Adds the stylesheet XML tags to the RSS.

Parameters:

Returns:

  • (nil)


15
16
17
18
19
# File 'lib/html2rss/rss_builder/stylesheet.rb', line 15

def add(maker, stylesheets)
  stylesheets.each do |stylesheet|
    add_stylesheet(maker, stylesheet)
  end
end

Instance Method Details

#to_xmlString

Returns the XML representation of the stylesheet.

Returns:

  • (String)

    the XML representation of the stylesheet



56
57
58
59
60
# File 'lib/html2rss/rss_builder/stylesheet.rb', line 56

def to_xml
  <<~XML
    <?xml-stylesheet href="#{href}" type="#{type}" media="#{media}"?>
  XML
end