Class: AtCoderFriends::Parser::SectionWrapper
- Inherits:
-
Object
- Object
- AtCoderFriends::Parser::SectionWrapper
- Defined in:
- lib/at_coder_friends/parser/section_wrapper.rb
Overview
holds section in problrem page
Instance Attribute Summary collapse
-
#h ⇒ Object
readonly
Returns the value of attribute h.
Instance Method Summary collapse
- #code_block ⇒ Object
- #content ⇒ Object
- #find_element(tags) ⇒ Object
-
#initialize(h) ⇒ SectionWrapper
constructor
A new instance of SectionWrapper.
- #siblings ⇒ Object
Constructor Details
#initialize(h) ⇒ SectionWrapper
Returns a new instance of SectionWrapper.
9 10 11 |
# File 'lib/at_coder_friends/parser/section_wrapper.rb', line 9 def initialize(h) @h = h end |
Instance Attribute Details
#h ⇒ Object (readonly)
Returns the value of attribute h.
7 8 9 |
# File 'lib/at_coder_friends/parser/section_wrapper.rb', line 7 def h @h end |
Instance Method Details
#code_block ⇒ Object
41 42 43 44 45 46 |
# File 'lib/at_coder_friends/parser/section_wrapper.rb', line 41 def code_block @code_block ||= begin elem = find_element(%w[pre blockquote]) (elem&.content || '').lstrip.gsub("\r\n", "\n") end end |
#content ⇒ Object
25 26 27 28 29 |
# File 'lib/at_coder_friends/parser/section_wrapper.rb', line 25 def content @content ||= begin siblings.reduce('') { |m, node| m + node.content.gsub("\r\n", "\n") } end end |
#find_element(tags) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/at_coder_friends/parser/section_wrapper.rb', line 31 def find_element() siblings.each do |node| .each do |tag| elem = node.name == tag ? node : node.search(tag)[0] return elem if elem end end nil end |
#siblings ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/at_coder_friends/parser/section_wrapper.rb', line 13 def siblings @siblings ||= begin ret = [] nx = h.next while nx && nx.name != h.name ret << nx nx = nx.next end ret end end |