Class: MarkdownMetrics::Elements::Sentence::Link

Inherits:
Base
  • Object
show all
Defined in:
lib/markdown_metrics/elements/sentence/link.rb

Instance Attribute Summary

Attributes inherited from Base

#skip_lines_until

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from MarkdownMetrics::Elements::Sentence::Base

Class Method Details

.match_element(character, next_character) ⇒ Object



7
8
9
# File 'lib/markdown_metrics/elements/sentence/link.rb', line 7

def self.match_element(character, next_character)
  character.to_s == '(' && next_character.to_s == '['
end

Instance Method Details

#attributesObject



28
29
30
31
32
33
# File 'lib/markdown_metrics/elements/sentence/link.rb', line 28

def attributes
  link_text = @final_value.match(/^\(\[(?<link_text>.*)\]/)['link_text']
  link_href = @final_value.match(/\((?<link>(http|https).*)\)/)['link'].gsub(")", "")

  { text: link_text, href: link_href, value: nil }
end

#nameObject



11
12
13
# File 'lib/markdown_metrics/elements/sentence/link.rb', line 11

def name
  :link
end

#valueObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/markdown_metrics/elements/sentence/link.rb', line 15

def value
  @final_value = nil

  @value.each_character_with_index_from(@start_at + 2) do |chr2, index2|
    next unless @value[index2..(index2 + 1)] == '))'
    @final_value = @value[@start_at..(index2 + 1)]
    @skip_lines_until = index2 + 1
    break
  end

  @final_value
end