Class: FeedElementInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/feed_element_installer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element_name, feed) ⇒ FeedElementInstaller

Returns a new instance of FeedElementInstaller.



18
19
20
21
22
23
# File 'lib/feed_element_installer.rb', line 18

def initialize(element_name, feed)
  @feed = feed
  @original_name = element_name
  @element_namespace, @element_name = *element_name.split(":")
  @element_accessor = "#{@element_namespace}_#{@element_name}"
end

Instance Attribute Details

#element_accessorObject (readonly)

Returns the value of attribute element_accessor.



16
17
18
# File 'lib/feed_element_installer.rb', line 16

def element_accessor
  @element_accessor
end

#element_nameObject (readonly)

Returns the value of attribute element_name.



16
17
18
# File 'lib/feed_element_installer.rb', line 16

def element_name
  @element_name
end

#element_namespaceObject (readonly)

Returns the value of attribute element_namespace.



16
17
18
# File 'lib/feed_element_installer.rb', line 16

def element_namespace
  @element_namespace
end

#feedObject (readonly)

Returns the value of attribute feed.



16
17
18
# File 'lib/feed_element_installer.rb', line 16

def feed
  @feed
end

#original_nameObject (readonly)

Returns the value of attribute original_name.



16
17
18
# File 'lib/feed_element_installer.rb', line 16

def original_name
  @original_name
end

Class Method Details

.install(element_name, feed) ⇒ Object



9
10
11
12
13
14
# File 'lib/feed_element_installer.rb', line 9

def self.install(element_name, feed)
  # RSS Specification at http://cyber.harvard.edu/rss/rss.html#extendingRss
  # > A RSS feed may contain [non-standard elements], only if those elements are *defined in a namespace*

  new(element_name, feed).install if element_name.include?(":")
end

Instance Method Details

#element_uriObject



25
26
27
28
# File 'lib/feed_element_installer.rb', line 25

def element_uri
  @element_uri ||=
    REXML::Document.new(feed).root&.attributes&.namespaces&.fetch(@element_namespace, "") || ""
end

#installObject



30
31
32
33
# File 'lib/feed_element_installer.rb', line 30

def install
  install_in_rss unless installed_in_rss?
  install_in_atom unless installed_in_atom?
end