conjugate 1.0

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.
data/.DS_Store ADDED
Binary file
Binary file
data/conjugate.gemspec ADDED
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'conjugate'
3
+ s.version = '1.0'
4
+ s.date = '2012-02-15'
5
+ s.summary = "Conjugate Verbs using a version of the templates defined here http://en.wiktionary.org/wiki/Category:Spanish_conjugation-table_templates"
6
+ s.description = s.summary
7
+ s.authors = ["Jeremy Geros"]
8
+ s.email = 'jeremy@govocab.com'
9
+
10
+ s.files = `git ls-files`.split("\n")
11
+ s.require_paths = ["lib"]
12
+
13
+ s.homepage = ''
14
+ end
data/lib/.DS_Store ADDED
Binary file
Binary file
@@ -0,0 +1,77 @@
1
+ require 'conjugate/templates/spanish_templates'
2
+ require 'conjugate/templates/spanish_irregular_verbs'
3
+
4
+ module Conjugate
5
+ module Spanish
6
+ extend self
7
+
8
+ def generate_list_of_know_irregular_verbs
9
+ puts "- " + SpanishIrregularVerbs.keys.sort.join("\n- ")
10
+ end
11
+
12
+ @dividing_infinitive_regex = /\{{3}\d+\}{3}(\w+)/
13
+
14
+
15
+ def conjugate(opts ={})
16
+ template = template(opts)
17
+ tense = tense(opts[:tense])
18
+
19
+ verb = opts[:verb]
20
+
21
+ infinitive = template[:infinitive].dup
22
+ verb_parts = divide_infinitive(infinitive, verb)
23
+
24
+ return nil if template[tense].nil? || template[tense][opts[:pronoun].to_sym].nil?
25
+
26
+ conjugation_template = template[tense][opts[:pronoun].to_sym].dup
27
+ positions = conjugation_template.scan(/\{{3}(\d+)\}{3}/).flatten
28
+
29
+ positions.each do |p|
30
+ conjugation_template.gsub!(/\{{3}#{p}\}{3}/, verb_parts[p.to_i - 1])
31
+ end
32
+ conjugation_template
33
+
34
+ end
35
+
36
+ def find_irregular(verb)
37
+ SpanishIrregularVerbs[verb]
38
+ end
39
+
40
+ def regular_ending(verb)
41
+ verb[-2..-1]
42
+ end
43
+
44
+ def template(opts)
45
+ SpanishTemplates[(opts[:template] || find_irregular(opts[:verb]) || regular_ending(opts[:verb])).to_sym]
46
+ end
47
+
48
+ def tense(t)
49
+ (common_name(t) || :present).to_sym
50
+ end
51
+
52
+ def common_name(t)
53
+ return nil unless t
54
+ changable_names = {:past => :preterite}
55
+ tense = changable_names[t.to_sym] || t
56
+ tense
57
+ end
58
+
59
+ def divide_infinitive(infinitive, verb)
60
+ inserts = infinitive.scan(@dividing_infinitive_regex).flatten
61
+
62
+ word_parts = []
63
+ word_copy = verb.dup
64
+
65
+ inserts.each do |letters|
66
+ sub_word = word_copy.scan(/(.+)#{letters}/).flatten.first
67
+ sub_word ||= ""
68
+
69
+ word_parts << sub_word
70
+ word_copy = word_copy.gsub(/^#{sub_word}#{letters}/, '')
71
+ end
72
+ word_parts << word_copy unless word_copy == ""
73
+ word_parts
74
+ end
75
+
76
+ end
77
+ end