Class: Bridgetown::Webfinger::JRD
- Inherits:
-
Object
- Object
- Bridgetown::Webfinger::JRD
- Includes:
- Logging
- Defined in:
- lib/bridgetown/webfinger/jrd.rb
Overview
A model of a [JSON Resource Descriptor]
Instance Attribute Summary collapse
-
#aliases ⇒ Array<Alias>?
readonly
The list of Aliases for the resource.
-
#links ⇒ Array<Link>?
readonly
The list of Links for the resource.
-
#properties ⇒ Properties?
readonly
The list of Properties for the resource.
-
#subject ⇒ String?
readonly
The subject of the JRD.
Class Method Summary collapse
-
.parse(subject, data) ⇒ JRD?
Parses and maybe-returns a JRD when the subject and data form one.
Instance Method Summary collapse
-
#initialize(aliases: nil, links: nil, properties: nil, subject: nil) ⇒ JRD
constructor
Creates a new JRD.
-
#to_h ⇒ Hash
private
Converts the JRD to a JSON-serializable Hash.
Methods included from Logging
Constructor Details
#initialize(aliases: nil, links: nil, properties: nil, subject: nil) ⇒ JRD
Creates a new Bridgetown::Webfinger::JRD
81 82 83 84 85 86 |
# File 'lib/bridgetown/webfinger/jrd.rb', line 81 def initialize(aliases: nil, links: nil, properties: nil, subject: nil) @aliases = aliases @links = links @properties = properties @subject = subject end |
Instance Attribute Details
#aliases ⇒ Array<Alias>? (readonly)
The list of Aliases for the resource
102 103 104 |
# File 'lib/bridgetown/webfinger/jrd.rb', line 102 def aliases @aliases end |
#links ⇒ Array<Link>? (readonly)
The list of Links for the resource
118 119 120 |
# File 'lib/bridgetown/webfinger/jrd.rb', line 118 def links @links end |
#properties ⇒ Properties? (readonly)
The list of Properties for the resource
134 135 136 |
# File 'lib/bridgetown/webfinger/jrd.rb', line 134 def properties @properties end |
#subject ⇒ String? (readonly)
The subject of the Bridgetown::Webfinger::JRD
147 148 149 |
# File 'lib/bridgetown/webfinger/jrd.rb', line 147 def subject @subject end |
Class Method Details
.parse(subject, data) ⇒ JRD?
Parses and maybe-returns a Bridgetown::Webfinger::JRD when the subject and data form one
Bridgetown::Webfinger::JRDs can describe any resource identifiable via a URI, whether you want to give public directory information about people via ‘acct:` URIs, copyright information about an article, or perhaps license information about a library.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bridgetown/webfinger/jrd.rb', line 51 def self.parse(subject, data) aliases = Array(data[:aliases]).filter_map { |moniker| Alias.parse(moniker) } links = Array(data[:links]).filter_map { |link| Link.parse(link) } properties = Properties.parse(data[:properties]) subject = Webfinger.uri?(subject) ? subject : nil new( aliases: (!aliases.empty?) ? aliases : nil, links: (!links.empty?) ? links : nil, properties: properties, subject: subject ) end |
Instance Method Details
#to_h ⇒ Hash
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.
Converts the Bridgetown::Webfinger::JRD to a JSON-serializable Hash
155 156 157 158 159 160 161 |
# File 'lib/bridgetown/webfinger/jrd.rb', line 155 def to_h result = {subject: subject} result[:aliases] = aliases if aliases result[:links] = links.map(&:to_h) if links result[:properties] = properties.to_h if properties result end |