Class: Character

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

Constant Summary collapse

@@all =
Array.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_yearObject (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_colorObject (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_colorObject (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

#heightObject (readonly)

Returns the value of attribute height.



2
3
4
# File 'lib/star_wars_finder/character.rb', line 2

def height
  @height
end

#homeworldObject (readonly)

Returns the value of attribute homeworld.



2
3
4
# File 'lib/star_wars_finder/character.rb', line 2

def homeworld
  @homeworld
end

#massObject (readonly)

Returns the value of attribute mass.



2
3
4
# File 'lib/star_wars_finder/character.rb', line 2

def mass
  @mass
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/star_wars_finder/character.rb', line 2

def name
  @name
end

#speciesObject (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

.allObject



12
13
14
# File 'lib/star_wars_finder/character.rb', line 12

def self.all
    @@all
end

.has_name?(name) ⇒ Boolean

Returns:

  • (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_10Object



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