Class: AtCoderFriends::Parser::IntroductionWrapper
- Inherits:
-
Object
- Object
- AtCoderFriends::Parser::IntroductionWrapper
- Defined in:
- lib/at_coder_friends/parser/introduction_wrapper.rb
Overview
holds introduction of problrem page
Instance Attribute Summary collapse
-
#div ⇒ Object
readonly
Returns the value of attribute div.
Instance Method Summary collapse
- #extract_intro(node) ⇒ Object
- #html ⇒ Object
-
#initialize(div) ⇒ IntroductionWrapper
constructor
A new instance of IntroductionWrapper.
- #intro ⇒ Object
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
#div ⇒ Object (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 |
#html ⇒ Object
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 |
#intro ⇒ Object
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 |