Class: Whatsa::Article
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#sections ⇒ Object
Returns the value of attribute sections.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #choose_section(choice) ⇒ Object
- #full_text ⇒ Object
-
#initialize(noko_doc) ⇒ Article
constructor
A new instance of Article.
- #section_titles ⇒ Object
- #summary ⇒ Object
Methods included from Format
#bulletize_lines, #heading_to_title, #remove_citation_markers, #url_friendly, #word_wrap
Constructor Details
#initialize(noko_doc) ⇒ Article
Returns a new instance of Article.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/whatsa/article.rb', line 11 def initialize(noko_doc) @title = noko_doc.css('h1').text content_text = noko_doc.css('#mw-content-text') wiki_parser_output = content_text.css('.mw-parser-output') # no idea why wiki is structured like this @contents = wiki_parser_output.empty? ? content_text.children : wiki_parser_output.children @sections = build_sections(noko_doc) # comment out the next line if you want sections with non-<p> and non-<ul> # content to display as "[no displayable information]" remove_empty_sections end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
9 10 11 |
# File 'lib/whatsa/article.rb', line 9 def contents @contents end |
#sections ⇒ Object
Returns the value of attribute sections.
8 9 10 |
# File 'lib/whatsa/article.rb', line 8 def sections @sections end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/whatsa/article.rb', line 9 def title @title end |
Instance Method Details
#choose_section(choice) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/whatsa/article.rb', line 40 def choose_section(choice) if choice.to_i > 0 sections[choice.to_i - 1] else get_section_by_title(choice) end end |
#full_text ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/whatsa/article.rb', line 28 def full_text return no_text_found for_subject: 'full summary' if sections.empty? # name might be a little confusing: it's not really the "full text" of the # article, it's the full text of the article summary. I'm naming it #full_text # for duck-typing reasons sections.first.full_text end |
#section_titles ⇒ Object
36 37 38 |
# File 'lib/whatsa/article.rb', line 36 def section_titles sections.map { |s| s.title } end |
#summary ⇒ Object
23 24 25 26 |
# File 'lib/whatsa/article.rb', line 23 def summary return no_text_found for_subject: 'summary' if sections.empty? sections.first.summary end |