hablaba 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/hablaba.rb +105 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8355d72088423e97ea296cbece13b77806a4ee34
4
+ data.tar.gz: 9c836edee9677de9ff653f7737669bf8dc762fe2
5
+ SHA512:
6
+ metadata.gz: 519f314946752285b387bd90a2456d8f3467289e3b633e29aedf04a3f83bf28511382dc01f15c71a0e712652daee818f19a7c8e40031414cbf0bd80c98eaa126
7
+ data.tar.gz: 7709147f6219867842ee1b137a3efcfe5221d4804309768a6ed31c4b4b5d88374f22916593686beb3eb5b9d0e008ef40f4406f5e1cda8dad6033bd4d30ad194a
data/lib/hablaba.rb ADDED
@@ -0,0 +1,105 @@
1
+ # accented chars for copying into an editor: é ú á í ñ ó
2
+
3
+ class Hablaba
4
+
5
+ class << self
6
+
7
+ # Conjugate a Spanish verb
8
+ #
9
+ # Example:
10
+ # >> Hablaba.conjugate('yo', 'hablar')
11
+ # => hablo
12
+ #
13
+ # Arguments:
14
+ # pronoun: (String)
15
+ # verb: (String)
16
+ # tense: (Symbol)
17
+ # - optional, defaults to :present
18
+ # - options: :present, :preterite, :imperfect
19
+ def conjugate(pronoun, verb, tense = :present)
20
+ case tense
21
+ when :present
22
+ conjugate_in_the_present(pronoun, verb)
23
+ when :preterite
24
+ conjugate_in_the_preterite(pronoun, verb)
25
+ when :imperfect
26
+ conjugate_in_the_imperfect(pronoun, verb)
27
+ else
28
+ # TODO: raise error
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def pronouns
35
+ %W[yo tú él ella nosotros vosotros ellos ellas usted ustedes]
36
+ end
37
+
38
+ def pronoun_index(pronoun)
39
+ [/yo/,/tú/,/él\z|ella\z|usted\z/,/nosotros/,/vosotros/,/ellos|ellas|ustedes/].index { |p| p =~ pronoun }
40
+ end
41
+
42
+ def get_verb_ending_and_root(verb)
43
+ verb_ending = /ar\z|er\z|ir\z/.match(verb)[0]
44
+ root = verb.gsub(/#{verb_ending}\z/, '')
45
+ return verb_ending, root
46
+ end
47
+
48
+ def conjugate_in_the_present(pronoun, verb)
49
+ verb_ending, root = get_verb_ending_and_root(verb)
50
+ case verb_ending
51
+ when 'ar' then conjugate_ar_in_the_present(pronoun, root)
52
+ when 'er' then conjugate_er_in_the_present(pronoun, root)
53
+ when 'ir' then conjugate_ir_in_the_present(pronoun, root)
54
+ end
55
+ end
56
+
57
+ def conjugate_ar_in_the_present(pronoun, root_of_verb)
58
+ root_of_verb + %W[o as a amos áis an][pronoun_index(pronoun)]
59
+ end
60
+
61
+ def conjugate_er_in_the_present(pronoun, root_of_verb)
62
+ root_of_verb + %W[o es e emos éis en][pronoun_index(pronoun)]
63
+ end
64
+
65
+ def conjugate_ir_in_the_present(pronoun, root_of_verb)
66
+ root_of_verb + %W[o es e imos ís en][pronoun_index(pronoun)]
67
+ end
68
+
69
+ def conjugate_in_the_preterite(pronoun, verb)
70
+ verb_ending, root = get_verb_ending_and_root(verb)
71
+ if verb_ending == 'ar'
72
+ conjugate_ar_in_the_preterite(pronoun, root)
73
+ else # er and ir are the same
74
+ conjugate_er_ir_in_the_preterite(pronoun, root)
75
+ end
76
+ end
77
+
78
+ def conjugate_ar_in_the_preterite(pronoun, root_of_verb)
79
+ root_of_verb + %W[é aste ó amos asteis aron][pronoun_index(pronoun)]
80
+ end
81
+
82
+ def conjugate_er_ir_in_the_preterite(pronoun, root_of_verb)
83
+ root_of_verb + %W[í iste ió imos isteis ieron][pronoun_index(pronoun)]
84
+ end
85
+
86
+ def conjugate_in_the_imperfect(pronoun, verb)
87
+ verb_ending, root = get_verb_ending_and_root(verb)
88
+ if verb_ending == 'ar'
89
+ conjugate_ar_in_the_imperfect(pronoun, root)
90
+ else # er and ir are the same
91
+ conjugate_er_ir_in_the_imperfect(pronoun, root)
92
+ end
93
+ end
94
+
95
+ def conjugate_ar_in_the_imperfect(pronoun, root_of_verb)
96
+ root_of_verb + %W[aba abas aba ábamos abais aban][pronoun_index(pronoun)]
97
+ end
98
+
99
+ def conjugate_er_ir_in_the_imperfect(pronoun, root_of_verb)
100
+ root_of_verb + %W[ía ías ía íamos íais ían][pronoun_index(pronoun)]
101
+ end
102
+
103
+ end
104
+
105
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hablaba
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Duyzer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Hablaba conjugates regular Spanish verbs in multiple tenses
14
+ email: adrianduyzer@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/hablaba.rb
20
+ homepage: https://github.com/adriand/hablaba
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Hablaba Spanish verb conjugator
44
+ test_files: []