Class: MicroMicro::Relationship
- Inherits:
-
Object
- Object
- MicroMicro::Relationship
- Defined in:
- lib/micro_micro/relationship.rb
Instance Attribute Summary collapse
-
#collection ⇒ MicroMicro::RelationshipsCollection
The RelationshipsCollection to which this Relationship belongs.
Class Method Summary collapse
-
.from_context(context) ⇒ Array<MicroMicro::Relationship>
Extract Relationships from a context.
Instance Method Summary collapse
-
#href ⇒ String
The value of the node’s
href
attribute. -
#hreflang ⇒ String?
The value of the node’s
hreflang
attribute, if present. -
#initialize(node) ⇒ MicroMicro::Relationship
constructor
Parse a node for relationship data.
-
#inspect ⇒ String
:nocov:.
-
#media ⇒ String?
The value of the node’s
media
attribute, if present. -
#rels ⇒ Array<String>
An Array of unique values from node’s
rel
attribute. -
#text ⇒ String
The node’s text content.
-
#title ⇒ String?
The value of the node’s
title
attribute, if present. -
#to_h ⇒ Hash{Symbol => String}
Return the parsed Relationship as a Hash.
-
#type ⇒ String?
The value of the node’s
type
attribute, if present.
Constructor Details
permalink #initialize(node) ⇒ MicroMicro::Relationship
Parse a node for relationship data.
25 26 27 |
# File 'lib/micro_micro/relationship.rb', line 25 def initialize(node) @node = node end |
Instance Attribute Details
permalink #collection ⇒ MicroMicro::RelationshipsCollection
The MicroMicro::RelationshipsCollection to which this MicroMicro::Relationship belongs.
9 10 11 |
# File 'lib/micro_micro/relationship.rb', line 9 def collection @collection end |
Class Method Details
permalink .from_context(context) ⇒ Array<MicroMicro::Relationship>
Extract MicroMicro::Relationships from a context.
15 16 17 18 19 |
# File 'lib/micro_micro/relationship.rb', line 15 def self.from_context(context) context .css(%([href][rel]:not([rel=""]))) .filter_map { |node| new(node) unless Helpers.ignore_nodes?(node.ancestors) } end |
Instance Method Details
permalink #href ⇒ String
The value of the node’s href
attribute.
32 33 34 |
# File 'lib/micro_micro/relationship.rb', line 32 def href @href ||= node["href"] end |
permalink #hreflang ⇒ String?
The value of the node’s hreflang
attribute, if present.
39 40 41 |
# File 'lib/micro_micro/relationship.rb', line 39 def hreflang @hreflang ||= node["hreflang"]&.strip end |
permalink #inspect ⇒ String
:nocov:
46 47 48 49 50 |
# File 'lib/micro_micro/relationship.rb', line 46 def inspect "#<#{self.class}:#{format("%#0x", object_id)} " \ "href: #{href.inspect}, " \ "rels: #{rels.inspect}>" end |
permalink #media ⇒ String?
The value of the node’s media
attribute, if present.
56 57 58 |
# File 'lib/micro_micro/relationship.rb', line 56 def media @media ||= node["media"]&.strip end |
permalink #rels ⇒ Array<String>
An Array of unique values from node’s rel
attribute.
78 79 80 |
# File 'lib/micro_micro/relationship.rb', line 78 def rels @rels ||= Set[*node["rel"].split].to_a.sort end |
permalink #text ⇒ String
The node’s text content.
85 86 87 |
# File 'lib/micro_micro/relationship.rb', line 85 def text @text ||= node.text end |
permalink #title ⇒ String?
The value of the node’s title
attribute, if present.
92 93 94 |
# File 'lib/micro_micro/relationship.rb', line 92 def title @title ||= node["title"]&.strip end |
permalink #to_h ⇒ Hash{Symbol => String}
Return the parsed MicroMicro::Relationship as a Hash.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/micro_micro/relationship.rb', line 63 def to_h { href: href, rels: rels, hreflang: hreflang, media: media, title: title, type: type, text: text }.compact_blank! end |
permalink #type ⇒ String?
The value of the node’s type
attribute, if present.
99 100 101 |
# File 'lib/micro_micro/relationship.rb', line 99 def type @type ||= node["type"]&.strip end |