class HintMe::Hinter

entry point for all HintMe functionality

Public Class Methods

new() click to toggle source

creates a new {Hinter} instance

# File lib/hintme/hinter.rb, line 11
def initialize
  @api_client = API::Client.new
  @cheatsheet_printer = Cheatsheet::Printer.new
end

Public Instance Methods

hint(topic) click to toggle source

searches and prints a cheatsheet for a given topic to the console

if no cheatsheet is found for the given topic a error message will be printed to the console

@param topic [String]

# File lib/hintme/hinter.rb, line 24
def hint(topic)
  cheatsheet = cheatsheet_for_topic(topic)

  if cheatsheet
    print_cheatsheet(cheatsheet)
  else
    display_missing_cheatsheet_error(topic)
  end
end

Private Instance Methods

cheatsheet_for_topic(topic) click to toggle source

fetches the cheatsheet for a topic

@param topic [String] @return [String]

# File lib/hintme/hinter.rb, line 41
def cheatsheet_for_topic(topic)
  @api_client.search_cheatsheet_for_topic(topic)
end
display_missing_cheatsheet_error(topic) click to toggle source

displays a error message informing the user about the missing cheatsheet to the console

# File lib/hintme/hinter.rb, line 56
def display_missing_cheatsheet_error(topic)
  topic ||= 'escaping the void of notopic-island'

  puts ":( There isn't a cheatsheet for #{topic}." \
       ' Maybe you should request one at devhints.io'
end
print_cheatsheet(cheatsheet) click to toggle source

prints a cheatsheet to the console

@param cheatsheet [String]