class Spellr::InteractiveAdd

Attributes

reporter[R]
token[R]

Public Class Methods

new(token, reporter) click to toggle source
# File lib/spellr/interactive_add.rb, line 12
def initialize(token, reporter)
  @token = token
  @reporter = reporter

  puts ''
  ask_wordlist
end

Public Instance Methods

add_to_wordlist(choice) click to toggle source
# File lib/spellr/interactive_add.rb, line 56
def add_to_wordlist(choice)
  wordlist = find_wordlist(choice)
  wordlist << token
  reporter.increment(:total_added)
  puts "\nAdded #{red(token)} to the #{bold wordlist.name} wordlist"
  throw :check_file_from, token
end
addable_languages() click to toggle source
# File lib/spellr/interactive_add.rb, line 24
def addable_languages
  languages.select(&:addable?)
end
ask_wordlist() click to toggle source
# File lib/spellr/interactive_add.rb, line 32
def ask_wordlist
  addable_languages.each { |l| puts "  #{key l.key} #{l.name}" }
  puts "  [^#{bold 'C'}] to go back"
  print "  Add #{red(token)} to which wordlist? "
  reporter.prompt_for_key

  handle_wordlist_choice
end
find_wordlist(key) click to toggle source
# File lib/spellr/interactive_add.rb, line 64
def find_wordlist(key)
  addable_languages.find { |w| w.key == key }.project_wordlist
end
handle_ctrl_c() click to toggle source
# File lib/spellr/interactive_add.rb, line 41
def handle_ctrl_c
  reporter.clear_line(language_keys.length + 6)
  reporter.call(token)
end
handle_wordlist_choice() click to toggle source
# File lib/spellr/interactive_add.rb, line 46
def handle_wordlist_choice
  choice = reporter.stdin_getch("#{language_keys.join}\u0003")
  # :nocov:
  case choice
  # :nocov:
  when "\u0003" then handle_ctrl_c
  when *language_keys then add_to_wordlist(choice)
  end
end
language_keys() click to toggle source
# File lib/spellr/interactive_add.rb, line 28
def language_keys
  @language_keys ||= addable_languages.map(&:key)
end
languages() click to toggle source
# File lib/spellr/interactive_add.rb, line 20
def languages
  @languages ||= Spellr.config.languages_for(token.location.file)
end
puts(str) click to toggle source
# File lib/spellr/interactive_add.rb, line 68
def puts(str)
  reporter.puts(str)
end