class Marvel101::Topic
Constants
- LINE_LEN
Attributes
description[RW]
name[RW]
scraped[RW]
urls[RW]
Public Class Methods
all()
click to toggle source
# File lib/marvel_101/topic.rb, line 72 def self.all @@all end
find_or_create_by_name(name, url)
click to toggle source
# File lib/marvel_101/topic.rb, line 67 def self.find_or_create_by_name(name, url) search = @@all.detect {|topic| topic.name == name} search ? search : self.new(name, url) end
new(name, url)
click to toggle source
# File lib/marvel_101/topic.rb, line 9 def initialize(name, url) @name = name @urls = {url: url} @scraped = false @@all << self end
Public Instance Methods
char?()
click to toggle source
# File lib/marvel_101/topic.rb, line 63 def char? self.is_a?(Marvel101::Character) end
display_description()
click to toggle source
# File lib/marvel_101/topic.rb, line 22 def display_description if description format_output("DESCRIPTION: #{description}") puts "" if "DESCRIPTION: #{description}".size > 60 end end
display_links()
click to toggle source
# File lib/marvel_101/topic.rb, line 29 def display_links puts "" if urls.size > 1 ["wiki", "101"].each do |url| output = "*Marvel #{url} available! Type '#{url}' to open in browser*" puts output if urls.include?("url_#{url}".to_sym) end end
format_output(text)
click to toggle source
# File lib/marvel_101/topic.rb, line 37 def format_output(text) i = LINE_LEN while i < text.size line_break = text[0..i].rindex(" ") puts text[i - LINE_LEN...line_break] i = line_break + LINE_LEN + 1 end puts text[i - LINE_LEN..-1] end
get_info()
click to toggle source
# File lib/marvel_101/topic.rb, line 16 def get_info scraper = Marvel101::Scraper.new(self) self.list? ? scraper.scrape_list : scraper.scrape_topic @scraped = true end
has_team?()
click to toggle source
# File lib/marvel_101/topic.rb, line 51 def has_team? char? && team end
list?()
click to toggle source
# File lib/marvel_101/topic.rb, line 55 def list? self.is_a?(Marvel101::List) end
takes_input?()
click to toggle source
# File lib/marvel_101/topic.rb, line 47 def takes_input? list? || (team? && !members.empty?) end
team?()
click to toggle source
# File lib/marvel_101/topic.rb, line 59 def team? self.is_a?(Marvel101::Team) end