class AtCoderFriends::Parser::SectionWrapper
holds a section of problrem page
Attributes
h[R]
Public Class Methods
new(h)
click to toggle source
# File lib/at_coder_friends/parser/section_wrapper.rb, line 9 def initialize(h) @h = h end
Public Instance Methods
code_block(mtd)
click to toggle source
# File lib/at_coder_friends/parser/section_wrapper.rb, line 55 def code_block(mtd) elem = find_element(%w[pre blockquote]) elem && elem.send(mtd).lstrip.gsub("\r\n", "\n") || '' end
code_block_content()
click to toggle source
# File lib/at_coder_friends/parser/section_wrapper.rb, line 47 def code_block_content @code_block_content ||= code_block(:content) end
code_block_html()
click to toggle source
# File lib/at_coder_friends/parser/section_wrapper.rb, line 51 def code_block_html @code_block_html ||= code_block(:to_html) end
content()
click to toggle source
# 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)
click to toggle source
# File lib/at_coder_friends/parser/section_wrapper.rb, line 37 def find_element(tags) elem = nil siblings.any? do |node| tags.any? do |tag| elem = node.name == tag ? node : node.search(tag)[0] end end elem end
html()
click to toggle source
# File lib/at_coder_friends/parser/section_wrapper.rb, line 31 def html @html ||= begin siblings.reduce('') { |m, node| m + node.to_html }.gsub("\r\n", "\n") end end
siblings()
click to toggle source
# 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