Method: Faker::Movies::StarWars.quote

Defined in:
lib/faker/movies/star_wars.rb

.quote(character = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/faker/movies/star_wars.rb', line 47

def quote(character = nil)
  quoted_characters = translate('faker.star_wars.quotes')

  if character.nil?
    character = sample(quoted_characters.keys).to_s
  else
    character = character.to_s.downcase

    # check alternate spellings, nicknames, titles of characters
    translate('faker.star_wars.alternate_character_spellings').each do |k, v|
      character = k.to_s if v.include?(character)
    end

    unless quoted_characters.key?(character.to_sym)
      raise ArgumentError, "Character for quotes can be left blank or #{quoted_characters.keys.join(', ')}"
    end
  end

  fetch('star_wars.quotes.' + character)
end