Class: Smartdict::Formats::TextColorFormat

Inherits:
AbstractFormat show all
Defined in:
lib/smartdict/formats/text_color_format.rb

Direct Known Subclasses

TextFormat

Instance Method Summary collapse

Methods inherited from AbstractFormat

format_list, format_translation, set_description

Instance Method Details

#format_list(translations) ⇒ Object

:nodoc:



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/smartdict/formats/text_color_format.rb', line 21

def format_list(translations)
  result = ""
  translations.each do |translation|
    translated_words = translation.translated.values.map{|words| words.first(3)}.flatten

    result << green(translation.word)
    result << " - "
    result << translated_words.join(", ")
    result << "\n"
  end
  result
end

#format_translation(translation) ⇒ Object

:nodoc:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/smartdict/formats/text_color_format.rb', line 5

def format_translation(translation)
  result = "#{bold_green(translation.word)}"
  result << green(" [#{translation.transcription}]") if translation.transcription
  result << "\n"

  translation.translated.each do |word_class, words|
    result << "  #{bold(word_class)}\n"
    words.each do |word|
      result << "    #{word}\n"
    end
  end

  result
end