Class: DictionaryRB_CLI

Inherits:
Thor
  • Object
show all
Defined in:
bin/dictionary

Instance Method Summary collapse

Instance Method Details

#examples(word = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'bin/dictionary', line 61

def examples(word=nil)
  write_file = options[:write] ? File.open(File.expand_path(options[:write]), 'wb') : nil
  words = options_simplifier(word, options)
  method = options[:urban] ? :urban : :dictionary
  words.each do |word|
    obj = DictionaryRB::Word.new(word).method(method).call
    results = obj.examples.shuffle.first(
        options[:count] ? options[:count] : 1
    )
    say "#{word}'s examples: #{results.join(', ')}"
    write_file.puts("#{word}'s examples: #{results.join(', ')}") if write_file
  end
  write_file.close if write_file
end

#meaning(word = nil) ⇒ Object



14
15
16
17
18
19
20
# File 'bin/dictionary', line 14

def meaning(word=nil)
  if options[:urban]
    invoke :urban, [word], options
  else
    urban_or_dictionary_meaning(word, options, :dictionary)
  end
end

#similar(word = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'bin/dictionary', line 40

def similar(word=nil)
  write_file = options[:write] ? File.open(File.expand_path(options[:write]), 'wb') : nil
  words = options_simplifier(word, options)
  method = options[:urban] ? :urban : :dictionary
  words.each do |word|
    obj = DictionaryRB::Word.new(word).method(method).call
    results = obj.similar_words.shuffle.first(
        options[:count] ? options[:count] : 1)
    say "#{word} is similar to - #{results.join(', ')}"
    write_file.puts("#{word} is similar to - #{results.join(', ')}") if write_file
  end
  write_file.close if write_file
end

#urban(word = nil) ⇒ Object



29
30
31
# File 'bin/dictionary', line 29

def urban(word=nil)
  urban_or_dictionary_meaning(word, options, :urban)
end