conjugatefr 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/conjugatefr +2 -5
- data/lib/conjugatefr.rb +66 -60
- data/lib/conjugatefr/renderers.rb +36 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87362c4221617c2625e90c78bda16876536213a7
|
4
|
+
data.tar.gz: 83c504e5139117a9ca1a7ca5c5ae7676ad4c14a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 271d9ea391997af2de123c736747babea7df9fbee0363bc7724ca2ead3a54fccd98d591517b359e25889c1efa22cf49a8748f7f8c51a2d19c8dd11f37afd6162
|
7
|
+
data.tar.gz: e6f2145bbcf1b1adb7064c769b576241f618efeab29298fa7d41c9c79e7b47bee07436cff142aca902bad4f2dc421fbcc6a5fa4d426efc75c5db71bf21f9c2ee
|
data/bin/conjugatefr
CHANGED
@@ -10,12 +10,10 @@ options = {
|
|
10
10
|
"renderer" => "Human",
|
11
11
|
}
|
12
12
|
|
13
|
-
cfr = ConjugateFR.new
|
14
|
-
|
15
13
|
OptionParser.new do |opts|
|
16
14
|
opts.banner = "Usage: #{$0} [options] [verbs]"
|
17
15
|
opts.program_name = "ConjugateFR"
|
18
|
-
opts.version = "1.0.
|
16
|
+
opts.version = "1.0.1"
|
19
17
|
opts.on "-R", "--require PATH", "Require PATH before running." do |path|
|
20
18
|
require path
|
21
19
|
end
|
@@ -51,5 +49,4 @@ unless renderer
|
|
51
49
|
exit -1
|
52
50
|
end
|
53
51
|
|
54
|
-
|
55
|
-
cfr.go ARGV
|
52
|
+
conjugateFR ARGV, renderer
|
data/lib/conjugatefr.rb
CHANGED
@@ -2,71 +2,77 @@ require 'open-uri'
|
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'conjugatefr/renderers'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
vouloir"
|
5
|
+
# Conjugates French Verbs
|
6
|
+
# @param query [Array] The query list. Can be null, in which presets are used.
|
7
|
+
# @param renderer [Renderer] The Renderer to use.
|
8
|
+
def conjugateFR (query, renderer)
|
9
|
+
# cpwords - Copy/Pasted words list from the website.
|
10
|
+
cpwords = "accroître acheter acquérir acquiescer
|
11
|
+
alléger aller apercevoir appeler
|
12
|
+
apprendre arguer arrêter asseoir
|
13
|
+
astreindre avoir battre boire
|
14
|
+
bouillir briller céder changer
|
15
|
+
chanter circoncire commencer compléter
|
16
|
+
conclure conduire confire confondre
|
17
|
+
connaître construire coudre courir
|
18
|
+
craindre créer croire croître
|
19
|
+
cueillir défaillir déléguer dépecer
|
20
|
+
devoir dire disséquer dissoudre
|
21
|
+
distinguer distraire dormir écrire
|
22
|
+
employer ennuyer enseigner entendre
|
23
|
+
envoyer espérer essayer essuyer
|
24
|
+
être faire falloir finir
|
25
|
+
fuir geler grasseyer interdire
|
26
|
+
interpeller jeter joindre lancer
|
27
|
+
lever lire louer luire
|
28
|
+
manger marquer maudire mener
|
29
|
+
mentir mettre mordre moudre
|
30
|
+
mouiller mourir mouvoir naître
|
31
|
+
naviguer nettoyer nuire offrir
|
32
|
+
oublier ouvrir pallier paraître
|
33
|
+
partir payer peindre peler
|
34
|
+
perdre peser plaire pleuvoir
|
35
|
+
pourvoir pouvoir prendre prévoir
|
36
|
+
prier promouvoir rapiécer recevoir
|
37
|
+
régner remuer répandre répondre
|
38
|
+
résoudre réveiller rire rompre
|
39
|
+
savoir semer sentir servir
|
40
|
+
signer sortir souffrir suffire
|
41
|
+
suivre surseoir taire tenir
|
42
|
+
tomber tordre traire travailler
|
43
|
+
tressaillir vaincre valoir vendre
|
44
|
+
venir vêtir vivre voir
|
45
|
+
vouloir"
|
47
46
|
|
48
|
-
|
49
|
-
|
47
|
+
# Generate word arrays from above list.
|
48
|
+
words = cpwords.gsub(/[ \t\n]+/, " ").split " "
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
# Fall back to presets
|
51
|
+
toqry = if query.empty?
|
52
|
+
words
|
53
|
+
else
|
54
|
+
query
|
55
|
+
end
|
56
56
|
|
57
|
-
|
57
|
+
# Filter out all of the accented words.
|
58
|
+
toqry_filtered = toqry.map { |word| word.gsub(/[êé]/, "e").gsub /î/, "i" }
|
58
59
|
|
59
|
-
|
60
|
+
# Render pre-word content.
|
61
|
+
renderer.pre
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
63
|
+
# Query each word.
|
64
|
+
toqry_filtered.each_with_index do |word, index|
|
65
|
+
open "http://conjf.cactus2000.de/showverb.en.php?verb=#{word}" do |page|
|
66
|
+
# Split the conjugations into an array.
|
67
|
+
doc = Nokogiri::HTML page
|
68
|
+
arr = doc.css("td [width='50%']").css("div").to_s.gsub(/.*?<div>/im, "").split("<br>")
|
69
|
+
arr.pop
|
69
70
|
|
70
|
-
|
71
|
+
# Render this word.
|
72
|
+
renderer.word toqry[index], arr
|
73
|
+
end
|
71
74
|
end
|
75
|
+
|
76
|
+
# Render post-word content.
|
77
|
+
renderer.post
|
72
78
|
end
|
@@ -1,13 +1,29 @@
|
|
1
1
|
# Ruby ConjugateFR Renderers - Part of Ruby ConjugateFR.
|
2
2
|
# I, htmlguy, hereby release this work into the public domain.
|
3
3
|
|
4
|
+
# Renders conjugated french verbs.
|
5
|
+
# (see conjugateFR)
|
4
6
|
class Renderer
|
7
|
+
# Prints content to go before the conjugations.
|
5
8
|
def pre; end
|
9
|
+
# Prints a verb and it's conjugations.
|
10
|
+
# @param name [String] The verb.
|
11
|
+
# @param words [Array] An array of conjugations.
|
6
12
|
def word (name, words); end
|
13
|
+
# Prints content to go after the conjugations.
|
7
14
|
def post; end
|
15
|
+
# The description of this renderer.
|
16
|
+
# For example: +Renders in the example format.+
|
17
|
+
# @return [String] the description.
|
8
18
|
def description; ""; end
|
9
19
|
end
|
10
20
|
|
21
|
+
# A renderer in a human-readable format.
|
22
|
+
# Output looks like:
|
23
|
+
# == someverb ==
|
24
|
+
# someconjugation
|
25
|
+
# someconjugation
|
26
|
+
# etc...
|
11
27
|
class HumanRenderer < Renderer
|
12
28
|
def word (name, words)
|
13
29
|
puts "\n == #{name} == "
|
@@ -18,6 +34,9 @@ class HumanRenderer < Renderer
|
|
18
34
|
def description; "Renders in a nice, human-readable format."; end
|
19
35
|
end
|
20
36
|
|
37
|
+
# A renderer template for rendering in a delimitered table format.
|
38
|
+
# (see CSVRenderer)
|
39
|
+
# (see TSVRenderer)
|
21
40
|
class DelimitedTableRenderer < Renderer
|
22
41
|
def initialize; @s = ""; end
|
23
42
|
def pre
|
@@ -32,16 +51,29 @@ class DelimitedTableRenderer < Renderer
|
|
32
51
|
end
|
33
52
|
end
|
34
53
|
|
54
|
+
# A renderer in the comma-separated value format.
|
55
|
+
# Output looks like:
|
56
|
+
# Word,Je,Tu,Il/Elle/On,Nous,Vous,Ils/Elles
|
57
|
+
# someverb,conj1,conj2,conj3,conj4,conj5,conj6
|
35
58
|
class CSVRenderer < DelimitedTableRenderer
|
36
59
|
def initialize; @s = ","; end
|
37
60
|
def description; "Renders in the Comma Separated Value (CSV) format."; end
|
38
61
|
end
|
39
62
|
|
63
|
+
# A renderer in the tab-separated value format.
|
64
|
+
# Output looks like (w/ 4-space tab):
|
65
|
+
# Word Je Tu Il/Elle/On Nous Vous Ils/Elles
|
66
|
+
# someverb conj1 conj2 conj3 conj4 conj5 conj6
|
40
67
|
class TSVRenderer < DelimitedTableRenderer
|
41
68
|
def initialize; @s = "\t"; end
|
42
69
|
def description; "Renders in the Tab Separated Value (TSV) format."; end
|
43
70
|
end
|
44
71
|
|
72
|
+
# A renderer in the markdown table syntax.
|
73
|
+
# Output looks like:
|
74
|
+
# |Word|Je|Tu|Il/Elle/On|Nous|Vous|Ils/Elles
|
75
|
+
# |---|---|---|---|---|---|---
|
76
|
+
# |someverb|conj1|conj2|conj3|conj4|conj5|conj6
|
45
77
|
class MDTableRenderer < Renderer
|
46
78
|
def pre
|
47
79
|
puts "|Word|Je|Tu|Il/Elle/On|Nous|Vous|Ils/Elles"
|
@@ -57,6 +89,7 @@ class MDTableRenderer < Renderer
|
|
57
89
|
def description; "Renders in Markdown's table syntax."; end
|
58
90
|
end
|
59
91
|
|
92
|
+
# Renders verbs in the form of a count of how many there are.
|
60
93
|
class CounterRenderer < Renderer
|
61
94
|
def initialize; @count = 0; end
|
62
95
|
def word (name, words)
|
@@ -68,6 +101,9 @@ class CounterRenderer < Renderer
|
|
68
101
|
def description; "Renders out a count of how many words are listed."; end
|
69
102
|
end
|
70
103
|
|
104
|
+
# A global list of renderers, with each one assigned to it's human-readable
|
105
|
+
# name.
|
106
|
+
# Used for programs like the CLI.
|
71
107
|
$renderers = {
|
72
108
|
"Human" => HumanRenderer.new,
|
73
109
|
"CSV" => CSVRenderer.new,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conjugatefr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- htmlguy
|
@@ -10,7 +10,23 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: A simple program to conjugate french verbs
|
13
|
+
description: "\n A simple program and library to conjugate french verbs.\n Parses
|
14
|
+
responses to requests to an online reference site.\n\n == Executable\n ConjugateFR
|
15
|
+
comes with the executable binary +conjugatefr+.\n To view information about it's
|
16
|
+
supported arguments, run\n conjugatefr --help\n\n == Custom Renderers\n To make
|
17
|
+
a custom renderer, just type\n require conjugatefr/renderer\n and then make a
|
18
|
+
class that extends +Renderer+.\n An example is as follows:\n\n require 'conjugatefr/renderer'\n
|
19
|
+
\ class ExampleRenderer < Renderer\n def pre\n puts \"This goes before
|
20
|
+
the words.\"\n end\n def word (name, words)\n print \"#{name}:\"\n
|
21
|
+
\ words.each do |word|\n print \" #{word}\"\n end\n end\n
|
22
|
+
\ def post\n puts \"This goes after the words.\"\n end\n def
|
23
|
+
description; \"Renders an example format.\"; end\n end\n # Add to the Renderers
|
24
|
+
list (For CLI and other programs that use it.)\n $renderers[\"Example\"] = ExampleRenderer.new\n
|
25
|
+
\ To try this out, save it as +erend.rb+ and then run:\n conjugatefr -R ./erend.rb
|
26
|
+
-r Example\n It will produce the output:\n This goes before the words.\n someword:
|
27
|
+
someconjugation etc etc\n ... (more words will be here)\n This goes after
|
28
|
+
the words.\n\n == The Library\n The library can be included with +require conjugatefr+.
|
29
|
+
It includes the\n +ConjugateFR+ class.\n "
|
14
30
|
email: htmlguy@pdum.xyz
|
15
31
|
executables:
|
16
32
|
- conjugatefr
|