Class: Gemtext::Link

Inherits:
Node
  • Object
show all
Defined in:
lib/gemtext/link.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#inspect

Constructor Details

#initialize(content) ⇒ Link

Returns a new instance of Link.



6
7
8
9
10
# File 'lib/gemtext/link.rb', line 6

def initialize(content)
  super content
  @target = @content.split(/\s+/).first
  @description = content.delete_prefix(@target).strip
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/gemtext/link.rb', line 3

def description
  @description
end

#targetObject (readonly)

Returns the value of attribute target.



4
5
6
# File 'lib/gemtext/link.rb', line 4

def target
  @target
end

Class Method Details

.[](target, description = nil) ⇒ Object



12
13
14
# File 'lib/gemtext/link.rb', line 12

def self.[](target, description = nil)
  new "#{target} #{description}"
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  other.class == self.class && other.target == @target && other.description == @description
end

#deconstruct_keys(*_keys) ⇒ Object



20
21
22
# File 'lib/gemtext/link.rb', line 20

def deconstruct_keys(*_keys)
  { **super, target:, description: }
end