Class: Marvel101::Character

Inherits:
Topic
  • Object
show all
Defined in:
lib/marvel_101/character.rb

Constant Summary collapse

DETAIL_ORDER =
[:real_name, :height, :weight, :abilities, :powers,
:group_affiliations, :first_appearance, :origin]

Constants inherited from Topic

Topic::LINE_LEN

Instance Attribute Summary collapse

Attributes inherited from Topic

#description, #name, #scraped, #urls

Instance Method Summary collapse

Methods inherited from Topic

all, #char?, #display_description, #display_links, find_or_create_by_name, #format_output, #get_info, #has_team?, #initialize, #list?, #takes_input?, #team?

Constructor Details

This class inherits a constructor from Marvel101::Topic

Instance Attribute Details

#detailsObject

Returns the value of attribute details.



5
6
7
# File 'lib/marvel_101/character.rb', line 5

def details
  @details
end

#listObject

Returns the value of attribute list.



5
6
7
# File 'lib/marvel_101/character.rb', line 5

def list
  @list
end

#teamObject

Returns the value of attribute team.



5
6
7
# File 'lib/marvel_101/character.rb', line 5

def team
  @team
end

Instance Method Details

#displayObject



10
11
12
13
14
15
# File 'lib/marvel_101/character.rb', line 10

def display
  display_description
  display_details
  display_links
  display_empty_message if no_info?
end

#display_detailsObject



17
18
19
20
21
22
23
24
25
# File 'lib/marvel_101/character.rb', line 17

def display_details
  DETAIL_ORDER.each do |type|
    if details.include?(type)
      title = type.to_s.split("_").join(" ").upcase
      format_output("#{title}: #{details[type]}")
      puts "" if "#{title}: #{details[type]}".size > 60
    end
  end
end

#display_empty_messageObject



27
28
29
30
# File 'lib/marvel_101/character.rb', line 27

def display_empty_message
  puts "Sorry, Marvel doesn't seem to care about #{name}"
  puts "Type 'source' to open source in browser, but don't get your hopes up"
end

#no_info?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/marvel_101/character.rb', line 32

def no_info?
  !description && details.empty? && urls.size <= 1
end

#valid_input?(input) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/marvel_101/character.rb', line 36

def valid_input?(input)
  false
end