Class: AtCoderFriends::Parser::IntroductionWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/at_coder_friends/parser/introduction_wrapper.rb

Overview

holds introduction of problrem page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(div) ⇒ IntroductionWrapper

Returns a new instance of IntroductionWrapper.



9
10
11
# File 'lib/at_coder_friends/parser/introduction_wrapper.rb', line 9

def initialize(div)
  @div = div
end

Instance Attribute Details

#divObject (readonly)

Returns the value of attribute div.



7
8
9
# File 'lib/at_coder_friends/parser/introduction_wrapper.rb', line 7

def div
  @div
end

Instance Method Details

#extract_intro(node) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/at_coder_friends/parser/introduction_wrapper.rb', line 21

def extract_intro(node)
  found = false
  node.children.each do |cld|
    found = true if %w[h2 h3].any? { |h| cld.name == h }
    if found
      cld.remove
    else
      found = extract_intro(cld)
    end
  end
  found
end

#htmlObject



34
35
36
# File 'lib/at_coder_friends/parser/introduction_wrapper.rb', line 34

def html
  @html ||= intro.to_html.gsub("\r\n", "\n")
end

#introObject



13
14
15
16
17
18
19
# File 'lib/at_coder_friends/parser/introduction_wrapper.rb', line 13

def intro
  @intro ||= begin
    div2 = div.dup
    extract_intro(div2)
    div2
  end
end