Class: Marvel101::Topic
- Inherits:
-
Object
- Object
- Marvel101::Topic
- Defined in:
- lib/marvel_101/topic.rb
Constant Summary collapse
- LINE_LEN =
80
- @@all =
[]
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#scraped ⇒ Object
Returns the value of attribute scraped.
-
#urls ⇒ Object
Returns the value of attribute urls.
Class Method Summary collapse
Instance Method Summary collapse
- #char? ⇒ Boolean
- #display_description ⇒ Object
- #display_links ⇒ Object
- #format_output(text) ⇒ Object
- #get_info ⇒ Object
- #has_team? ⇒ Boolean
-
#initialize(name, url) ⇒ Topic
constructor
A new instance of Topic.
- #list? ⇒ Boolean
- #takes_input? ⇒ Boolean
- #team? ⇒ Boolean
Constructor Details
#initialize(name, url) ⇒ Topic
Returns a new instance of Topic.
9 10 11 12 13 14 |
# File 'lib/marvel_101/topic.rb', line 9 def initialize(name, url) @name = name @urls = {url: url} @scraped = false @@all << self end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/marvel_101/topic.rb', line 3 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/marvel_101/topic.rb', line 3 def name @name end |
#scraped ⇒ Object
Returns the value of attribute scraped.
3 4 5 |
# File 'lib/marvel_101/topic.rb', line 3 def scraped @scraped end |
#urls ⇒ Object
Returns the value of attribute urls.
3 4 5 |
# File 'lib/marvel_101/topic.rb', line 3 def urls @urls end |
Class Method Details
.all ⇒ Object
72 73 74 |
# File 'lib/marvel_101/topic.rb', line 72 def self.all @@all end |
.find_or_create_by_name(name, url) ⇒ Object
67 68 69 70 |
# 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 |
Instance Method Details
#char? ⇒ Boolean
63 64 65 |
# File 'lib/marvel_101/topic.rb', line 63 def char? self.is_a?(Marvel101::Character) end |
#display_description ⇒ Object
22 23 24 25 26 27 |
# 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 ⇒ Object
29 30 31 32 33 34 35 |
# 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) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# 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 ⇒ Object
16 17 18 19 20 |
# 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? ⇒ Boolean
51 52 53 |
# File 'lib/marvel_101/topic.rb', line 51 def has_team? char? && team end |
#list? ⇒ Boolean
55 56 57 |
# File 'lib/marvel_101/topic.rb', line 55 def list? self.is_a?(Marvel101::List) end |
#takes_input? ⇒ Boolean
47 48 49 |
# File 'lib/marvel_101/topic.rb', line 47 def takes_input? list? || (team? && !members.empty?) end |