Class: Roebe::Translate

Inherits:
Base show all
Defined in:
lib/roebe/classes/translate.rb

Overview

Roebe::Translate

Constant Summary collapse

SCIENCE_DIRECTORY =
#

SCIENCE_DIRECTORY

Some helpful constants.

#
'/home/x/data/science/'
DEFAULT_WORD_TO_TRANSLATE =
#

DEFAULT_WORD_TO_TRANSLATE

#
'chagrin'
USE_COLOURS =
#

USE_COLOURS

#
true

Constants inherited from Base

Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#actions, #append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #complex_esystem, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #olivedrab, #open_in_browser, #opne, #opnesystem, #opnn, #orange, #orchid, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove, #remove_directory, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #show_help, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #touch, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into, #yellow

Methods included from Base::CommandlineArguments

#append_onto_the_commandline_arguments, #clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?, #set_commandline_arguments

Constructor Details

#initialize(i, run_already = false) ⇒ Translate

#

initialize

#


55
56
57
58
59
60
61
62
63
# File 'lib/roebe/classes/translate.rb', line 55

def initialize(
    i,
    run_already = false
  )
  reset
  set_this_word(i)
  load_data
  run if run_already
end

Instance Attribute Details

#from_language_to_languageObject

Returns the value of attribute from_language_to_language.



50
51
52
# File 'lib/roebe/classes/translate.rb', line 50

def from_language_to_language
  @from_language_to_language
end

#translate_unknown_wordsObject

Returns the value of attribute translate_unknown_words.



49
50
51
# File 'lib/roebe/classes/translate.rb', line 49

def translate_unknown_words
  @translate_unknown_words
end

Instance Method Details

#_(i) ⇒ Object

#

_

Use this method to append to @string.

#


249
250
251
# File 'lib/roebe/classes/translate.rb', line 249

def _(i)
  @string << i.dup
end

#add_revObject

#

add_rev

#


256
257
258
# File 'lib/roebe/classes/translate.rb', line 256

def add_rev
  _ rev
end

#enable_coloursObject

#

enable_colours

Use this method call to enable ansicolours.

#


138
139
140
141
142
# File 'lib/roebe/classes/translate.rb', line 138

def enable_colours
  @use_colours = true
  require 'colours/html_colours'
  Translate.class_eval { include Colours } # This is functionally the same as "include Colours"
end

#english_dictionary_include_this_key?(key) ⇒ Boolean

#

english_dictionary_include_this_key?

#

Returns:

  • (Boolean)


239
240
241
242
# File 'lib/roebe/classes/translate.rb', line 239

def english_dictionary_include_this_key?(key)
  value = @yaml_dataset.keys.include?(key)
  return value
end

#feedback_which_words_are_availableObject

#

feedback_which_words_are_available

#


165
166
167
168
# File 'lib/roebe/classes/translate.rb', line 165

def feedback_which_words_are_available
  _ "These words are available:#{N}"
  _ '  '+@yaml_dataset.keys.join(', ')
end

#found?Boolean

#

found?

#

Returns:

  • (Boolean)


102
103
104
# File 'lib/roebe/classes/translate.rb', line 102

def found?
  @found
end

#load_data(which_dictionary_to_use = @english_dictionary) ⇒ Object Also known as: reload_data

#

load_data

use reload_data to load new dataset.

#


149
150
151
# File 'lib/roebe/classes/translate.rb', line 149

def load_data(which_dictionary_to_use = @english_dictionary)
  load_yaml(which_dictionary_to_use)
end

#load_yaml(location) ⇒ Object

#

load_yaml

Sets the variable @yaml_dataset.

#


158
159
160
# File 'lib/roebe/classes/translate.rb', line 158

def load_yaml(location)
  @yaml_dataset = YAML.load_file(location)
end

#output_resultObject

#

output_result

Simply output the result.

#


272
273
274
# File 'lib/roebe/classes/translate.rb', line 272

def output_result
  e @string
end

#output_result=(i) ⇒ Object

#

output_result=

#


279
280
281
# File 'lib/roebe/classes/translate.rb', line 279

def output_result=(i)
  @output_result = i
end

#resetObject

#

reset (reset tag)

#


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/roebe/classes/translate.rb', line 68

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @output_result
  # ======================================================================= #
  @output_result = true
  # ======================================================================= #
  # === @english_dictionary
  # ======================================================================= #
  @english_dictionary = Dictionaries.file_english
  # ======================================================================= #
  # === @found
  # ======================================================================= #
  @found = false
  # ======================================================================= #
  # === @translate_unknown_words
  # ======================================================================= #
  @translate_unknown_words = false
  enable_colours if USE_COLOURS # Determine whether to enable ansicolours or not.
  reset_string
  set_from_language_to_language
end

#reset_stringObject

#

reset_string

#


95
96
97
# File 'lib/roebe/classes/translate.rb', line 95

def reset_string # Just reset the @string variable here.
  @string = ''.dup
end

#set_foundObject

#

set_found

#


173
174
175
# File 'lib/roebe/classes/translate.rb', line 173

def set_found
  @found = true
end

#set_from_language_to_language(i = :english_to_german) ⇒ Object

#

set_from_language_to_language

#


127
128
129
130
131
# File 'lib/roebe/classes/translate.rb', line 127

def set_from_language_to_language(i = :english_to_german)
  i = :english_to_german if i.to_s == 'random'
  i = :english_to_german if i.to_s == 'default' # default tag.
  @from_language_to_language = i
end

#set_this_word(i = :random) ⇒ Object

#

set_this_word

#


116
117
118
119
120
121
122
# File 'lib/roebe/classes/translate.rb', line 116

def set_this_word(i = :random)
  i = DEFAULT_WORD_TO_TRANSLATE if i.nil?
  i = i.to_s if i.is_a? Symbol
  i = i.first if i.is_a? Array
  i = i.downcase # Downcasing this since AUG 2009.
  @this_word = i # this word will be translated
end

#string?Boolean Also known as: string

#

string?

#

Returns:

  • (Boolean)


263
264
265
# File 'lib/roebe/classes/translate.rb', line 263

def string?
  @string
end

#this_word?Boolean Also known as: this_word

#

this_word?

#

Returns:

  • (Boolean)


109
110
111
# File 'lib/roebe/classes/translate.rb', line 109

def this_word?
  @this_word
end

#translate(from_language_to_language = @from_language_to_language, word_to_be_translated = @this_word) ⇒ Object Also known as: run

#

translate (translate tag, trans tag)

This method will translate between different dictionaries, such as from english to german or vice versa etc …

However, it may later also serve as jumping point to other, general translate methods and operations.

Invocation examples:

trans mite
trans ?
#


192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/roebe/classes/translate.rb', line 192

def translate(
    from_language_to_language = @from_language_to_language,
    word_to_be_translated     = @this_word
  )
  @found = false
  reset_string # set to empty again.
  set_this_word(word_to_be_translated)
  case from_language_to_language.to_s
  when 'english_to_german','default','def',''
    set_this_word(@yaml_dataset.keys.shuffle[0]) if @this_word.to_s == 'random'
    if @this_word == '?' # Wenn fragezeichen
      feedback_which_words_are_available
      set_found
    else
      @found = true
      if english_dictionary_include_this_key?(@this_word)
        _ GREEN if @use_colours
        _ '  `'
        _ LIGHTBLUE if @use_colours
        _ @this_word
        _ GREEN if @use_colours
        _ '` is translated to `'
        _ LIGHTBLUE if @use_colours
        _ @yaml_dataset[@this_word]
        _ GREEN if @use_colours
        _ '` in german.'
      elsif english_dictionary_include_this_key?(@this_word+'ed')
        _ '  `'+@this_word+'` is translated to `'+
          @yaml_dataset[@this_word+'ed']+'` in german.'
      elsif english_dictionary_include_this_key?(@this_word+'d')
        _ '  `'+@this_word+'` is translated to `'+
          @yaml_dataset[@this_word+'d']+'` in german.'
      else
        @found = false
        _ 'English word `'+@this_word+'` was not found.'
      end
      add_rev
    end
  else
    e 'Not knowing '+sfancy(from_language_to_language)
  end
  output_result if @output_result
end