class Formatter::FORMATARTICLE

Public Class Methods

body(article) click to toggle source
# File lib/berklee_valencia/formatter.rb, line 35
def self.body(article)
  article.body.each do |paragraph|
    if paragraph.match(/-{3} /)
      puts " ______________________________________________________________________________"
      puts "  ||               Press enter to scroll to the next section                ||"
      puts "  ||                or type 'end' to skip to end of article.                ||"
      puts " ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾"
      input = gets.strip
      if input == "end"
        return "end"
      end
      puts "#{wrap(paragraph)}"
      puts ""
    elsif !paragraph.match(/click here/i) && !paragraph.match(/•/)
      if paragraph.match(/below:/) || paragraph.match(/^Watch|^Listen/)
        media_compiler(article, paragraph)
      else
        puts "#{wrap(paragraph)}"
        puts ""
      end #nestedif
    end #if
  end #do
end
border_maker(article) click to toggle source
# File lib/berklee_valencia/formatter.rb, line 21
def self.border_maker(article)
  border = ""
  bordertestlength = [article.title.length, (article.author.length + article.date.length + 5)].max
  borderlength = [bordertestlength, 80].min
  borderlength.times {border << "-"}
  border
end
end(article) click to toggle source
# File lib/berklee_valencia/formatter.rb, line 74
def self.end(article)
  puts ""
  puts " ______________________________________________________________________________"
  puts "  ||                          END OF ARTICLE                                ||"
  puts "  ||              Type 'open' to see full article in browser                ||"
  puts "  ||                    or hit enter to see all options                     ||"
  puts " ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾"
  2.times {puts ""}
  input = gets.strip
  if input == "open"
    system("open #{article.url}")
  end
end
gap_maker(article, border) click to toggle source
# File lib/berklee_valencia/formatter.rb, line 29
def self.gap_maker(article, border)
  gap = ""
  (border.length - article.author.length - article.date.length).times {gap << " "}
  gap
end
header(article) click to toggle source
# File lib/berklee_valencia/formatter.rb, line 11
def self.header(article)
  border = border_maker(article)
  puts ""
  2.times {puts "#{border}"}
  puts "#{wrap(article.title)}"
  gap = gap_maker(article, border)
  puts "#{article.author}#{gap}#{article.date}"
  2.times {puts "#{border}"}
end
media_compiler(article, paragraph) click to toggle source
# File lib/berklee_valencia/formatter.rb, line 59
def self.media_compiler(article, paragraph)
  if paragraph.match(/below:/)
    puts " - - - - - - - - - - - - - - - - - Media - - - - - - - - - - - - - - - - - - -"
    puts "#{wrap(paragraph)}"
    puts "#{urlwrap("        Visit #{(article.related_links.shift)}")}"
    puts "#{urlwrap("        Visit #{(article.related_links.shift)}")}"
    puts " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
  elsif paragraph.match(/^Watch|^Listen/i)
    puts " - - - - - - - - - - - - - - - - - Media - - - - - - - - - - - - - - - - - - -"
    puts "#{wrap(paragraph)}"
    puts "#{urlwrap("        Visit #{(article.related_links.shift)}")}"
    puts " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
  end
end