Class: Greeter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path = (__dir__ + '/data/languages.json')) ⇒ Greeter

Returns a new instance of Greeter.



4
5
6
# File 'lib/greeter.rb', line 4

def initialize(file_path = (__dir__ + '/data/languages.json'))
  @languages = load_languages file_path
end

Instance Attribute Details

#languagesObject (readonly)

Returns the value of attribute languages.



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

def languages
  @languages
end

Instance Method Details

#greet_in(language, vlad, say) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
# File 'lib/greeter.rb', line 8

def greet_in(language, vlad, say)
  language = language.to_s.downcase
  raise ArgumentError, "#{language.upcase} LANGUAGE NOT FOUND!" if @languages[language].nil?
  string = @languages[language.to_s.downcase].to_s.chomp
  string << ", vlad." if vlad
  puts string if say
  string
end