Sprichwoerter 0.1 → 1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
Binary file
@@ -0,0 +1,117 @@
1
+ ==========
2
+ PROVERBS
3
+ ==========
4
+ ----------------------------------------------------------
5
+ Rearrange proverbs into new, mostly senseless, proverbs.
6
+ ----------------------------------------------------------
7
+
8
+ *Sprichwörter* is the German name for the same program.
9
+
10
+ Synopsis
11
+ ========
12
+
13
+ **proverbs**
14
+
15
+ **proverbs -[qc <COLOR>] (--qualify --color <COLOR>)**
16
+
17
+ **proverbs -f (--favorites)**
18
+
19
+ **proverbs -a (--add)**
20
+
21
+ **proverbs -h (--help)**
22
+
23
+ **proverbs -v (--version)**
24
+
25
+ DESCRIPTION
26
+ ============
27
+ The program combines the beginnings and the endings of proverbs randomly picked
28
+ from a list. The result is a phrase which is still recognizable as "kind of a
29
+ proverb" but without claiming to convey any real message, let alone "wisdom".
30
+
31
+ Yes. It is intended as a humorous waste of time. You can, for example, call
32
+ proverbs from your *.bashrc* file.
33
+
34
+ When called on the command-prompt as **proverbs** without any options, a newly
35
+ generated proverb will be printed out on screen.
36
+
37
+ OPTIONS
38
+ ============
39
+
40
+ **-a** or **--add**
41
+ Allows you to add a new, real proverb to the list of original proverbs. You
42
+ are prompted for each of the details: language (one of *en* or *de* at the
43
+ time of this writing), singular or plural (*s*, *p*), beginning and ending of
44
+ the proverb.
45
+
46
+ **-f** or **--favorites**
47
+ Will dump the list of "qualified", random proverbs, i.e. those that had been
48
+ found worth saving after a previous call to proverbs.
49
+
50
+ **-q** or **--qualify**
51
+ After a newly created proverb has been presented, you have a few seconds to
52
+ eventually qualify a proverb, i.e. add it to the list of favorites, by
53
+ pushing '+'.
54
+
55
+ **-c** or **--color=COLOR**
56
+ Sets the color the border which sourrounds a generated proverb. Must be one
57
+ of red, green, yellow, purple, cyan, blue, white or black.
58
+
59
+ **-h** or **--help**
60
+ Shows the short help-text for the program.
61
+
62
+ **-v** or **--version**
63
+ Shows version-information
64
+
65
+ ADDING PROVERBS to the default list (option -a or --add)
66
+ ------------------------------------------------------------
67
+ At the time of this writing (october 2019), original ('real') proverbs must
68
+ conform to the pattern
69
+
70
+ "*someone or something*" | "**does or is** *something*"
71
+
72
+ Just execute the program a few times on the command-line, without arguments, to
73
+ get the idea.
74
+
75
+ For the time, original proverbs are grouped with respect to their subject
76
+ (someone or something), which is uncountable or in singular for the first group
77
+ (like in “Fortune | favors the bold”), in plural for the second group (like
78
+ in “All Roads | lead to Rome”).
79
+
80
+ FILES
81
+ ==================
82
+
83
+ The hidden directory *.proverbs* in the user's home-directory can contain three
84
+ types of file. For the English version, these are:
85
+
86
+ *liste_en.rb*
87
+ This file contains all the currently available, original proverbs. It exists
88
+ only, if you have already added new original proverbs.
89
+
90
+ *liste_en_bak.rb*
91
+ A backup-copy of the previous version of the list of proverbs.
92
+
93
+ *qualifile_en*
94
+ This file contains the list of previously qualified, randomly generated
95
+ proverbs, i.e. the list of *favorites*. It is created when you qualify a
96
+ proverb for the very first time, and dumped to screen, when you use the
97
+ option -f or --favorites.
98
+
99
+ OTHER INFORMATION
100
+ ==================
101
+ :Source-code: "Proverbs" had been developed in Ruby and is distributed as a
102
+ ruby-gem. If you installed the program from the gem-file (with
103
+ *gem install*), then you find all the source-files in the
104
+ gem-folder for your Ruby-version. Otherwise, you can also unpack
105
+ the gem-file (with *tar*), then uncompress the data-archive and
106
+ take a look at the files in the resulting, new folders *bin* and
107
+ *lib*.
108
+ :License: "Proverbs" is released under the conditions of the
109
+ GNU General Public License, version 3.0.
110
+ :Version: 1.6 of 2019/10/15
111
+ :Author: "Proverbs" has been programmed by Michael Uplawski
112
+ <michael.uplawski@uplawski.eu>. The German parlor game
113
+ *"Verrückte Sprichwörter"* ("Crazy Proverbs") was the principal
114
+ inspiration for the project.
115
+
116
+ **Ω**
117
+
@@ -0,0 +1,123 @@
1
+ ===============
2
+ Sprichwoerter
3
+ ===============
4
+ ------------------------------------------------------------------------------------------
5
+ Kombiniert Anfänge und Enden von Sprichwörtern zu neuen, meist sinnlosen, Sprichwörtern.
6
+ ------------------------------------------------------------------------------------------
7
+ *Proverbs* - Der englische Name für das gleiche Programm.
8
+
9
+ Programmaufruf
10
+ ====================
11
+
12
+ **sprichwoerter**
13
+
14
+ **sprichwoerter -[wf <FARBE>] (--werten --farbe=<FARBE>)**
15
+
16
+ **sprichwoerter -l (--liste)**
17
+
18
+ **sprichwoerter -n (--neu)**
19
+
20
+ **sprichwoerter -h (--help)**
21
+
22
+ **sprichwoerter -v (--version)**
23
+
24
+
25
+ Beschreibung
26
+ ===================
27
+ Das Programm kombiniert die Anfänge und Enden von zufällig aus einer Liste
28
+ ausgewählten Sprichwörtern. Das Ergebnis ist ein Satz, der immer noch als eine
29
+ Art „Sprichwort“ erkennbar ist, allerdings ohne den Anspruch, eine wirkliche
30
+ Information zu vermitteln, geschweige denn „Weisheit“.
31
+
32
+ Ja. Eine lustige Zeitverschwendung. Sie können das Programm „Sprichwörter“ zum
33
+ Beispiel aus Ihrer *.bashrc* Datei aufrufen.
34
+
35
+ Wenn **Sprichwörter** ohne Argumente von der Kommandozeile gestartet wird,
36
+ erzeugt es ein neues Sprichwort und zeigt es an.
37
+
38
+ OPTIONEN
39
+ ===================
40
+
41
+ **-n** oder **--neu**
42
+ Erlaubt es, neue aber echte Sprichwörter zur Liste der originalen
43
+ Sprichwörter hinzuzufügen. Sie werden zur Eingabe jedes notwendigen Details
44
+ einzeln aufgefordert: Sprache (zur Zeit eines von *en* oder *de*), Singular
45
+ oder Plural (*s*, *p*), Beginn und Ende des Sprichworts.
46
+
47
+ **-l** oder **--liste**
48
+ Gibt die Liste der bereits bewerteten, zufälligen Sprichwörter auf dem
49
+ Bildschirm aus.
50
+
51
+ **-w** oder **--werten**
52
+ Wenn ein neu erzeugtes Sprichwort angezeigt wird, bleiben Ihnen einige
53
+ Sekunden, um es eventuell zu bewerten (durch drücken von '*+*') und damit in
54
+ die Liste der bewerteten Sprichwörter aufzunehmen.
55
+
56
+ **-f** oder **--farbe=FARBE**
57
+ Bestimmt die Farbe des Rahmens, der ein neu generiertes Sprichwort umgibt.
58
+ Der Farbname muss einer der folgenden sein: rot, grün, gelb, lila, cyan,
59
+ blau, weiß, schwarz.
60
+
61
+ **-h** oder **--hilfe**
62
+ Zeigt die Kurzhilfe zum Program.
63
+
64
+ **-v** or **--version**
65
+ Gibt Versions-Informationen aus.
66
+
67
+ SPRICHWÖRTER ZUR LISTE HINZUFÜGEN
68
+ --------------------------------------------
69
+ Zur Zeit der Redaktion dieses Dokuments (Oktober 2019) müssen Sprichwörter
70
+ dem im Folgenden beschriebenen Muster folgen:
71
+
72
+ "*Jemand oder etwas*" | "**tut oder ist** *etwas*"
73
+
74
+ Führen Sie das Programm einfach ein paar Mal auf der Kommandozeile aus, um
75
+ diese Einschränkung zu verstehen.
76
+
77
+ Bis auf weiteres werden originale Sprichwörter in zwei Gruppen eingeteilt:
78
+ diejenigen, deren Subjekt unzählbar ist oder im Singular steht (zum Beispiel
79
+ „Der Zweck | heiligt die Mittel“, „Hochmut | kommt vor dem Fall“) und die
80
+ zweite Gruppe von Sprichwörtern mit einem Subjekt im Plural (zum Beispiel
81
+ „Große Ereignisse | werfen ihre Schatten voraus“)
82
+
83
+ DATEIEN
84
+ ==================
85
+
86
+ Im versteckten Verzeichnis *.proverbs*, im Benutzerverzeichnis, können drei
87
+ Arten von Datei abgelegt sein. Für die deutsche Version sind das:
88
+
89
+ *liste_de.rb*
90
+ Diese Datei enthält alle augenblicklich verfügbaren originalen Sprichwörter.
91
+ Sie existiert nur, wenn Sie bereits ein solches Sprichwort zur Liste
92
+ hinzugefügt haben (mit Option *-n* oder *--neu*).
93
+
94
+ *liste_de_bak.rb*
95
+ Eine Sicherheitskopie der vorigen Version der Liste originaler Sprichwörter.
96
+
97
+ *qualifile_de*
98
+ Diese Datei enthält die Liste der bereits bewerteten, zufällig generierten
99
+ Sprichwörter. Sie wird erzeugt, wenn Sie zum ersten Mal eine Wertung
100
+ vornehmen. Später wird diese Liste angezeigt, wenn Sie das Programmargument
101
+ -l oder --liste verwenden.
102
+
103
+ ANDERE INFORMATIONEN
104
+ ====================
105
+ Das Gesellschaftsspiel "*Verrückte Sprichwörter*" diente als Inspiration für
106
+ die Entwicklung des Programms.
107
+
108
+ :Quellcode: "Sprichwörter" ist in Ruby programmiert und wird als Ruby-Gem
109
+ veröffentlicht. Wenn Sie das Programm aus der Gem-Datei installiert
110
+ haben, befinden sich alle Quellcode-Dateien im Gem-Ordner für Ihre
111
+ Ruby-Version. Anderenfalls können sie auch die Gem-Datei entpacken
112
+ (mit *tar*) und dann das data-Archiv dekomprimieren. Der Quellcode
113
+ befindet sich danach in den Verzeichnissen **bin** und **lib**.
114
+
115
+ :Version: 1.6 vom 15. Oktober 2019
116
+
117
+ :Lizenz: "Sprichwörter" ist freie Software gemäß den Bestimmungen der GNU GPL,
118
+ Version 3.0
119
+
120
+ :Autor: "Sprichwörter" wurde von Michael Uplawski
121
+ <michael.uplawski@uplawski.eu> programmiert.
122
+
123
+ **Ω**
@@ -0,0 +1,91 @@
1
+ #encoding: UTF-8
2
+ =begin
3
+ /***************************************************************************
4
+ * ©2016-2016 Michael Uplawski <michael.uplawski@uplawski.eu> *
5
+ * *
6
+ * This program is free software; you can redistribute it and/or modify *
7
+ * it under the terms of the GNU General Public License as published by *
8
+ * the Free Software Foundation; either version 3 of the License, or *
9
+ * (at your option) any later version. *
10
+ * *
11
+ * This program is distributed in the hope that it will be useful, *
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
+ * GNU General Public License for more details. *
15
+ * *
16
+ * You should have received a copy of the GNU General Public License *
17
+ * along with this program; if not, write to the *
18
+ * Free Software Foundation, Inc., *
19
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20
+ ***************************************************************************/
21
+ =end
22
+
23
+ require_relative 'color_output'
24
+ require_relative 'translating'
25
+ require_relative 'logging'
26
+ require 'readline'
27
+
28
+ class Adder
29
+ self.extend(Logging)
30
+ @@log = self.init_logger(STDOUT)
31
+ include Translating
32
+
33
+ # Initialize with a language code and specify singular or plural.
34
+ # Devide the proverb into "beginning" and "ending", mind the quotes!
35
+ def initialize(lang = 'de', sipl = 'singular', beginning, ending)
36
+ @log = @@log
37
+
38
+ details = ask_details
39
+ @log.debug('lang ' << @language)
40
+ @log.debug('sipl ' << @sipl)
41
+ @log.debug('beginning ' << @beginning)
42
+ @log.debug('ending ' << @ending)
43
+ listfile = trl('list') << '_' << @language
44
+ @log.debug('listfile is ' << listfile)
45
+ confdir = ENV['HOME'].dup << File::Separator << ".proverbs"
46
+ user_list = confdir.dup << File::Separator << listfile
47
+ listrb = user_list.dup << '.rb'
48
+ if File::exist?(listrb) && File.readable?(listrb)
49
+ require user_list
50
+ else
51
+ require_relative listfile
52
+ end
53
+ new_proverb = [@beginning, @ending]
54
+
55
+ case @sipl.downcase
56
+ when trl('s')
57
+ $proverbs1.push new_proverb
58
+
59
+ when trl('p')
60
+ $proverbs0.push new_proverb
61
+ else
62
+ puts red(trl("Cannot add the proverb, invalid argument") << ' ' << bold("#{sipl}") )
63
+ exit false
64
+ end
65
+
66
+ if !File.exist?(confdir)
67
+ Dir.mkdir(confdir)
68
+ end
69
+ File.rename(listrb, user_list.dup << '_bak.rb') if(File.exist?(listrb) )
70
+ File.open( listrb,'w') do |lfile|
71
+ lfile.puts "$proverbs0=" << $proverbs0.uniq.to_s
72
+ lfile.puts
73
+ lfile.puts "$proverbs1=" << $proverbs1.uniq.to_s
74
+ end
75
+ puts green(trl("List %s has been updated") %listrb )
76
+ end
77
+
78
+ private
79
+
80
+ def ask_details
81
+ @language = Readline.readline( trl("Language") << " (de, en): ")
82
+ @sipl = Readline.readline("\n" << trl("Singular or plural (s, p)") << (": ") )
83
+ @beginning = Readline.readline( "\n" << trl("Beginning of the proverb") << ": " )
84
+ @ending = Readline.readline( "\n" << trl("Ending of the proverb") << ": " )
85
+ end
86
+ end
87
+
88
+ # -- test
89
+ if __FILE__ == $0
90
+ Adder.new('en', 'singular', "no man", "is an island")
91
+ end
@@ -0,0 +1,128 @@
1
+ #encoding: UTF-8
2
+ =begin
3
+ /***************************************************************************
4
+ * ©2019-2019 Michael Uplawski <michael.uplawski@uplawski.eu> *
5
+ * *
6
+ * This program is free software; you can redistribute it and/or modify *
7
+ * it under the terms of the GNU General Public License as published by *
8
+ * the Free Software Foundation; either version 3 of the License, or *
9
+ * (at your option) any later version. *
10
+ * *
11
+ * This program is distributed in the hope that it will be useful, *
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
+ * GNU General Public License for more details. *
15
+ * *
16
+ * You should have received a copy of the GNU General Public License *
17
+ * along with this program; if not, write to the *
18
+ * Free Software Foundation, Inc., *
19
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20
+ ***************************************************************************/
21
+ =end
22
+
23
+
24
+ require 'optparse'
25
+ require 'optparse/time'
26
+ require 'ostruct'
27
+ require 'date'
28
+ require_relative 'translating'
29
+ require_relative 'version'
30
+
31
+ class ArgParser
32
+ extend Translating
33
+
34
+
35
+ def self.trl_color(localized_color)
36
+ color = %w~
37
+ red
38
+ green
39
+ purple
40
+ yellow
41
+ cyan
42
+ blue
43
+ white
44
+ black
45
+ ~.detect {|col| trl(col) == localized_color }
46
+ return color
47
+ end
48
+
49
+
50
+ # Returns a structure describing the options.
51
+ #
52
+ def self.parse(args)
53
+ # The options specified on the command line will be collected in <b>options</b>.
54
+ # We set default values here.
55
+ options = OpenStruct.new
56
+ options.qualify = false
57
+ options.color = 'white'
58
+ options.list = false
59
+ options.add = nil
60
+
61
+ op = OptionParser.new do |opts|
62
+ opts.banner = trl("Usage") << ":\t" << "%s <options>" %($0) <<"\n"
63
+
64
+ opts.separator ""
65
+ opts.separator trl("Specific options") << ":"
66
+
67
+ opts.on('-' << trl('a'), '--' << trl('add') , trl('Add real proverb to the base') ) do |g|
68
+ options.add = g
69
+ end
70
+
71
+ opts.on('-' << trl('f'), '--' << trl('favorites'), trl('Show favorites')) do
72
+ options.list = true
73
+ end
74
+
75
+ opts.on('-' << trl('q'), '--' << trl("qualify"), trl("Qualify proverbs")) do
76
+ options.qualify = true
77
+ end
78
+
79
+ opts.on('-' << trl('c'), '--' << trl('color') << '=' << trl('COLOR'), trl('Use color in program-output (one of red, green, yellow, purple, cyan, blue, white, black)')) do |col|
80
+ color = trl_color(col.strip)
81
+ if(color && [:red, :green, :yellow, :purple, :cyan, :blue, :white, :black].include?(color.strip.to_sym))
82
+ options.color = color
83
+ else
84
+ puts (trl("Error!") << ' ' << trl('Invalid color value') << ' "' << col << '"!')
85
+ usage()
86
+ exit false
87
+ end
88
+ end
89
+
90
+ opts.separator ""
91
+ opts.separator (trl("Common options")) << ':'
92
+
93
+ # No argument, shows at tail. This will print an options summary.
94
+ opts.on_tail('-' << trl('h'), '--' << trl('help'), (trl('Show this message') ) ) do
95
+ usage(opts)
96
+ end
97
+
98
+ opts.on_tail('-' << trl('v'), '--' << trl('version'), (trl('Show version and program information') )) do
99
+ puts "\t#{$0} #{VERSION}"
100
+ puts "\t© 2016-2019 Michael Uplawski <michael.uplawski at uplawski.eu>"
101
+ exit true
102
+ end
103
+ end
104
+ begin
105
+ op.parse!(args)
106
+ rescue OptionParser::MissingArgument => ex
107
+ puts trl(ex.reason) + " " << trl("for option") << " " << ex.args[0]
108
+ usage()
109
+ exit
110
+ rescue OptionParser::InvalidOption => ex
111
+ puts trl(ex.reason) + " " << ex.args[0]
112
+ usage()
113
+ exit
114
+ end
115
+ options
116
+ end # parse()
117
+
118
+ def self::usage(opts = nil)
119
+ if(opts)
120
+ puts opts
121
+ else
122
+ puts trl("Execute with option -h to see an option summary")
123
+ end
124
+ exit true
125
+
126
+ end
127
+ end
128
+