Class: Character
- Inherits:
-
Object
- Object
- Character
- Defined in:
- lib/star_wars_finder/character.rb
Constant Summary collapse
- @@all =
Array.new
Instance Attribute Summary collapse
-
#birth_year ⇒ Object
readonly
Returns the value of attribute birth_year.
-
#eye_color ⇒ Object
readonly
Returns the value of attribute eye_color.
-
#hair_color ⇒ Object
readonly
Returns the value of attribute hair_color.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#homeworld ⇒ Object
readonly
Returns the value of attribute homeworld.
-
#mass ⇒ Object
readonly
Returns the value of attribute mass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#species ⇒ Object
readonly
Returns the value of attribute species.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(p_hash) ⇒ Character
constructor
A new instance of Character.
Constructor Details
#initialize(p_hash) ⇒ Character
Returns a new instance of Character.
4 5 6 7 8 9 10 11 |
# File 'lib/star_wars_finder/character.rb', line 4 def initialize(p_hash) p_hash.each do |key, value| if self.class.instance_methods.include?(key.to_sym) self.instance_variable_set("@#{key}", value) end end @@all << self end |
Instance Attribute Details
#birth_year ⇒ Object (readonly)
Returns the value of attribute birth_year.
2 3 4 |
# File 'lib/star_wars_finder/character.rb', line 2 def birth_year @birth_year end |
#eye_color ⇒ Object (readonly)
Returns the value of attribute eye_color.
2 3 4 |
# File 'lib/star_wars_finder/character.rb', line 2 def eye_color @eye_color end |
#hair_color ⇒ Object (readonly)
Returns the value of attribute hair_color.
2 3 4 |
# File 'lib/star_wars_finder/character.rb', line 2 def hair_color @hair_color end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
2 3 4 |
# File 'lib/star_wars_finder/character.rb', line 2 def height @height end |
#homeworld ⇒ Object (readonly)
Returns the value of attribute homeworld.
2 3 4 |
# File 'lib/star_wars_finder/character.rb', line 2 def homeworld @homeworld end |
#mass ⇒ Object (readonly)
Returns the value of attribute mass.
2 3 4 |
# File 'lib/star_wars_finder/character.rb', line 2 def mass @mass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/star_wars_finder/character.rb', line 2 def name @name end |
#species ⇒ Object (readonly)
Returns the value of attribute species.
2 3 4 |
# File 'lib/star_wars_finder/character.rb', line 2 def species @species end |
Class Method Details
.all ⇒ Object
12 13 14 |
# File 'lib/star_wars_finder/character.rb', line 12 def self.all @@all end |
.has_name?(name) ⇒ Boolean
20 21 22 23 24 25 26 27 |
# File 'lib/star_wars_finder/character.rb', line 20 def self.has_name?(name) self.all.each do |person| if person.name.downcase.match?(name) CLI.display_search_res(person) else false end end end |
.top_10 ⇒ Object
15 16 17 18 19 |
# File 'lib/star_wars_finder/character.rb', line 15 def self.top_10 top_10_arr = ["Chewbacca", "C-3PO", "R2-D2", "Palpatine", "Obi-Wan Kenobi", "Luke Skywalker", "Leia", "Yoda", "Han Solo", "Darth Vader"] top_10_arr.sort.each { |person| puts "#{person}" } end |