Class: Omgcnb::UnreleasedMarkdown

Inherits:
Object
  • Object
show all
Defined in:
lib/omgcnb/unreleased_markdown.rb

Instance Method Summary collapse

Constructor Details

#initialize(markdown_text) ⇒ UnreleasedMarkdown

Returns a new instance of UnreleasedMarkdown.



5
6
7
# File 'lib/omgcnb/unreleased_markdown.rb', line 5

def initialize(markdown_text)
  @markdown_text = markdown_text
end

Instance Method Details

#changed_listObject



21
22
23
24
# File 'lib/omgcnb/unreleased_markdown.rb', line 21

def changed_list
  return [] unless unreleased_ul
  unreleased_ul.xpath("li").map {|li| "- #{li.content}" }
end

#htmlObject



13
14
15
# File 'lib/omgcnb/unreleased_markdown.rb', line 13

def html
  @html ||= Kramdown::Document.new(@markdown_text).to_html
end

#needs_release?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/omgcnb/unreleased_markdown.rb', line 9

def needs_release?
  unreleased_ul
end

#nokogiriObject



17
18
19
# File 'lib/omgcnb/unreleased_markdown.rb', line 17

def nokogiri
  @nokogiri ||= Nokogiri::HTML(html)
end

#search_ulObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/omgcnb/unreleased_markdown.rb', line 31

def search_ul
  # Find h2 header with "unreleased"
  # search to see if the next element is an "h2" (no unreleased changes)
  # or it is "ul" (has unreleased changes)
  node = unreleased_h2&.next_sibling
  while node
    node = node.next_sibling
    case node&.name
    when "h2"
      return nil
    when "ul"
      return node
    end
  end
end

#unreleased_h2Object



47
48
49
# File 'lib/omgcnb/unreleased_markdown.rb', line 47

def unreleased_h2
  nokogiri.xpath("//h2[@id='unreleased']").first
end

#unreleased_ulObject



26
27
28
29
# File 'lib/omgcnb/unreleased_markdown.rb', line 26

def unreleased_ul
  return @unreleased_ul if defined?(@unreleased_ul)
  @unreleased_ul = search_ul
end