Class: Whatsa::Article
- Inherits:
-
Object
- Object
- Whatsa::Article
- Defined in:
- lib/whatsa/article.rb
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
Constructor Details
#initialize(noko_doc) ⇒ Article
Returns a new instance of Article.
5 6 7 8 9 10 11 12 13 |
# File 'lib/whatsa/article.rb', line 5 def initialize(noko_doc) @title = noko_doc.css('h1').text @contents = noko_doc.css('#mw-content-text').children @sections = make_sections # 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.
3 4 5 |
# File 'lib/whatsa/article.rb', line 3 def contents @contents end |
#sections ⇒ Object
Returns the value of attribute sections.
2 3 4 |
# File 'lib/whatsa/article.rb', line 2 def sections @sections end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/whatsa/article.rb', line 3 def title @title end |
Instance Method Details
#choose_section(choice) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/whatsa/article.rb', line 30 def choose_section(choice) if choice.to_i > 0 self.sections[choice.to_i - 1] else get_section_by_title(title) end end |
#full_text ⇒ Object
19 20 21 22 23 24 |
# File 'lib/whatsa/article.rb', line 19 def full_text # 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 self.sections.first.full_text end |
#section_titles ⇒ Object
26 27 28 |
# File 'lib/whatsa/article.rb', line 26 def section_titles self.sections.map { |s| s.title } end |
#summary ⇒ Object
15 16 17 |
# File 'lib/whatsa/article.rb', line 15 def summary self.sections.first.summary end |