Class: Whatsa::Article

Inherits:
Object
  • Object
show all
Includes:
Format
Defined in:
lib/whatsa/article.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
# File 'lib/whatsa/article.rb', line 11

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

#contentsObject (readonly)

Returns the value of attribute contents.



9
10
11
# File 'lib/whatsa/article.rb', line 9

def contents
  @contents
end

#sectionsObject

Returns the value of attribute sections.



8
9
10
# File 'lib/whatsa/article.rb', line 8

def sections
  @sections
end

#titleObject (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



36
37
38
39
40
41
42
# File 'lib/whatsa/article.rb', line 36

def choose_section(choice)
  if choice.to_i > 0
    self.sections[choice.to_i - 1]
  else
    get_section_by_title(title)
  end
end

#full_textObject



25
26
27
28
29
30
# File 'lib/whatsa/article.rb', line 25

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_titlesObject



32
33
34
# File 'lib/whatsa/article.rb', line 32

def section_titles
  self.sections.map { |s| s.title }
end

#summaryObject



21
22
23
# File 'lib/whatsa/article.rb', line 21

def summary
  self.sections.first.summary
end