Module: RfcReader::Recent

Defined in:
lib/rfc_reader/recent.rb

Class Method Summary collapse

Class Method Details

.fetchString

Returns the raw XML from the recent RFCs RSS feed.

Returns:

  • (String)

    the raw XML from the recent RFCs RSS feed



18
19
20
21
22
# File 'lib/rfc_reader/recent.rb', line 18

def self.fetch
  ErrorContext.wrap("Fetching the recent RFCs list") do
    Net::HTTP.get(RECENT_RFCS_RSS_URI)
  end
end

.listHash<String, String>

Returns from RFC title to text file url.

Returns:

  • (Hash<String, String>)

    from RFC title to text file url



12
13
14
15
# File 'lib/rfc_reader/recent.rb', line 12

def self.list
  xml = fetch
  parse(xml)
end

.parse(xml) ⇒ Hash<String, String>

Example: XML fragment we’re trying to parse title and link data from.

“‘xml <item>

<title>
RFC 9624: EVPN Broadcast, Unknown Unicast, or Multicast (BUM) Using Bit Index Explicit Replication (BIER)
</title>
<link>https://www.rfc-editor.org/info/rfc9624</link>
<description>
This document specifies protocols and procedures for forwarding Broadcast, Unknown Unicast, or Multicast (BUM) traffic of Ethernet VPNs (EVPNs) using Bit Index Explicit Replication (BIER).
</description>

</item> “‘

Parameters:

  • xml (String)

    the XML of the recent RFCs RSS endpoint

Returns:

  • (Hash<String, String>)

    from RFC title to text file url



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rfc_reader/recent.rb', line 40

def self.parse(xml)
  ErrorContext.wrap("Parsing the recent RFCs list") do
    Nokogiri::XML(xml).xpath("//item").to_h do |item|
      item_hash = item.elements.to_h do |elem|
        [elem.name, elem.text.strip]
      end

      # The link is to the webpage and not the plaintext document so we must convert it.
      file_name = File.basename(item_hash.fetch("link"))

      [
        item_hash.fetch("title"),
        "https://www.rfc-editor.org/rfc/#{file_name}.txt",
      ]
    end
  end
end