Class: Bridgetown::Webfinger::Titles

Inherits:
Model
  • Object
show all
Defined in:
lib/bridgetown/webfinger/titles.rb

Overview

Wraps a ‘titles` member within a Link

Class Method Summary collapse

Methods included from Logging

included, #warn

Class Method Details

.parse(data) ⇒ Titles?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses and maybe-returns Bridgetown::Webfinger::Titles when the value is one

Titles within the JRD are name/value pairs [with language tag names and string values]. When the language is indeterminate, use ‘“und”`.

[1]: datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.4

Parameters:

  • data (Hash)

    the data to parse as a titles object

Returns:

  • (Titles, nil)

    the titles parsed from the data

Since:

  • 0.1.0



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bridgetown/webfinger/titles.rb', line 19

def self.parse(data)
  return unless data.is_a?(Hash)

  data = data.select do |key, value|
    if !key.is_a?(String)
      next warn("Webfinger title key is not a string: #{key}, ignoring")
    elsif !value.is_a?(String)
      next warn("Webfinger title value for #{key} is not a string: #{value}, ignoring")
    else
      true
    end
  end

  if !data.empty?
    new(data)
  else
    warn("All Webfinger link titles pruned: #{data.inspect}, ignoring")
  end
end