respanol 0.0.1

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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +50 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +15 -0
  5. data/Gemfile.lock +95 -0
  6. data/Guardfile +122 -0
  7. data/README.md +21 -0
  8. data/lib/respanol/ano.rb +8 -0
  9. data/lib/respanol/examenes/ano_examen.rb +20 -0
  10. data/lib/respanol/examenes/conjugacion_examen.rb +20 -0
  11. data/lib/respanol/examenes/examen_base.rb +53 -0
  12. data/lib/respanol/examenes/fecha_examen.rb +22 -0
  13. data/lib/respanol/examenes/hora_examen.rb +25 -0
  14. data/lib/respanol/examenes/numero_examen.rb +38 -0
  15. data/lib/respanol/examenes/semana_examen.rb +20 -0
  16. data/lib/respanol/fecha.rb +12 -0
  17. data/lib/respanol/hora.rb +43 -0
  18. data/lib/respanol/impresion.rb +23 -0
  19. data/lib/respanol/numero.rb +102 -0
  20. data/lib/respanol/pronombre.rb +81 -0
  21. data/lib/respanol/semana.rb +14 -0
  22. data/lib/respanol/traducir.rb +32 -0
  23. data/lib/respanol/traductor.rb +15 -0
  24. data/lib/respanol/verbos/aprender.rb +7 -0
  25. data/lib/respanol/verbos/caminar.rb +7 -0
  26. data/lib/respanol/verbos/dormir.rb +7 -0
  27. data/lib/respanol/verbos/entender.rb +7 -0
  28. data/lib/respanol/verbos/hablar.rb +7 -0
  29. data/lib/respanol/verbos/hacer.rb +7 -0
  30. data/lib/respanol/verbos/jugar.rb +7 -0
  31. data/lib/respanol/verbos/leer.rb +7 -0
  32. data/lib/respanol/verbos/poder.rb +7 -0
  33. data/lib/respanol/verbos/ser.rb +7 -0
  34. data/lib/respanol/verbos/subir.rb +7 -0
  35. data/lib/respanol/verbos/tener.rb +7 -0
  36. data/lib/respanol/verbos/tocar.rb +7 -0
  37. data/lib/respanol/verbos/verbo_base.rb +7 -0
  38. data/lib/respanol/verbos/viajar.rb +7 -0
  39. data/lib/respanol/verbos/vivir.rb +7 -0
  40. data/lib/respanol/version.rb +3 -0
  41. data/lib/respanol.rb +11 -0
  42. data/respanol.gemspec +30 -0
  43. data/spec/respanol/fecha_spec.rb +7 -0
  44. data/spec/respanol/hora_spec.rb +28 -0
  45. data/spec/respanol/impresion_spec.rb +15 -0
  46. data/spec/respanol/numero_spec.rb +99 -0
  47. data/spec/respanol_spec.rb +0 -0
  48. data/spec/spec_helper.rb +110 -0
  49. metadata +181 -0
@@ -0,0 +1,102 @@
1
+ module Respanol
2
+ class Numero
3
+ UNIDADES = %w( cero uno dos tres cuatro cinco seis siete ocho nueve )
4
+ DECENA = %w( diez once doce trece catorce quince dieciseis diecisiete dieciocho diecinueve )
5
+ DECENAS = %W( #{''} diez viente treinta cuarenta cincuenta sesenta setenta ochenta noventa )
6
+ CENTENARES = %W( #{''} ciento doscientos trescientos cuatrocientos quinientos seiscientos setecientos ochocientos novecientos )
7
+ UNO_APOCOPE = 'un'
8
+ MILLONS = %W( #{''} millon billon trillon cuatrillon quintillon sextillon septillon octillon nonillon decillon undecillon duodecillon tredecillon cuatordecillon quindecillon sexdecillon septendecillon octodecillon novendecillon vigintillon )
9
+ UNIDAD_1K = 'mil'
10
+ DECIMAL = 'coma'
11
+
12
+ def self.feminino
13
+ FemininoNumero
14
+ end
15
+
16
+ def self.unirse_palabras(*ps)
17
+ ps.flatten.join(' ').gsub(/\s+/, ' ').strip
18
+ end
19
+
20
+ def self.numero_en_palabras(numero)
21
+ return self::UNIDADES[0] if numero == 0
22
+
23
+ num = numero
24
+ millons = []
25
+ s_millons = []
26
+ es_unidad = true
27
+ i_millon = 0
28
+ loop do
29
+ # Obteno el millone
30
+ millon = num % 1_000_000
31
+ millons.push millon
32
+ # Escribo el millone
33
+ s_millons.push("#{MILLONS[i_millon]}#{'es' if millon > 1}") if !es_unidad && millon >= 1
34
+ s_millons.push millon_en_palabras(millon, es_unidad)
35
+ # Preparo a continuacion
36
+ es_unidad = false
37
+ i_millon += 1
38
+ num = num / 1_000_000
39
+
40
+ break if num == 0
41
+ end
42
+
43
+ unirse_palabras(s_millons.reverse)
44
+ end
45
+
46
+ def self.millon_en_palabras(numero, es_unidad = true)
47
+ num = numero % 1_000_000
48
+
49
+ s_ultimos_3 = tres_ultimos_en_palabras(num, es_unidad)
50
+
51
+ if num >= 1000
52
+ mil = (num % 1_000_000) / 1000
53
+ s_mil = case mil
54
+ when 0
55
+ ''
56
+ when 1
57
+ UNIDAD_1K
58
+ else
59
+ "#{tres_ultimos_en_palabras(mil, false)} #{UNIDAD_1K}"
60
+ end
61
+ end
62
+
63
+ unirse_palabras(s_mil, s_ultimos_3)
64
+ end
65
+
66
+ def self.dos_ultimos_en_palabras(num, es_unidad = true)
67
+ ultimos_2 = num % 100
68
+ ultimo = ultimos_2 % 10
69
+ case ultimos_2 / 10
70
+ when 2
71
+ ultimo == 0 ? DECENAS[2] : "vienti#{unidad(ultimo, es_unidad)}"
72
+ when 1
73
+ DECENA[ultimo]
74
+ else
75
+ s = "#{DECENAS[ultimos_2 / 10]}"
76
+ s = s + "#{' y ' if (ultimos_2 / 10 >= 3)}#{unidad(ultimo, es_unidad)}" if ultimo > 0
77
+ s
78
+ end
79
+ end
80
+
81
+ def self.tres_ultimos_en_palabras(num, es_unidad = true)
82
+ return 'cien' if (num % 1000) == 100
83
+
84
+ s_ultimos_2 = dos_ultimos_en_palabras(num, es_unidad)
85
+ s_centenar = self::CENTENARES[(num % 1000) / 100] if num >= 100
86
+ unirse_palabras(s_centenar, s_ultimos_2)
87
+ end
88
+
89
+ def self.unidad(num, es_unidad = true)
90
+ ultimo = num % 10
91
+ return self::UNO_APOCOPE if !es_unidad && ultimo == 1
92
+
93
+ self::UNIDADES[ultimo]
94
+ end
95
+ end
96
+
97
+ class FemininoNumero < Numero
98
+ UNIDADES = %w( cero una dos tres cuatro cinco seis siete ocho nueve )
99
+ CENTENARES = %W( #{''} ciento doscientas trescientas cuatrocientas quinientas seiscientas setecientas ochocientas novecientas )
100
+ UNO_APOCOPE = 'una'
101
+ end
102
+ end
@@ -0,0 +1,81 @@
1
+ module Respanol
2
+ class Pronombre
3
+ YO = 'Yo'
4
+ TU = 'Tu'
5
+ EL = 'El'
6
+ ELLA = 'Ella'
7
+ USTED = 'Usted'
8
+ NOSOTROS = 'Nosotros'
9
+ NOSOTRAS = 'Nosotras'
10
+ VOSOTROS = 'Vosotros'
11
+ VOSOTRAS = 'Vosotras'
12
+ ELLOS = 'Ellos'
13
+ ELLAS = 'Ellas'
14
+ USTEDES = 'Ustedes'
15
+
16
+ def self.todos
17
+ @all ||= [YO, TU, EL, ELLA, USTED, NOSOTROS, NOSOTRAS, VOSOTROS, VOSOTRAS, ELLOS, ELLAS, USTEDES]
18
+ end
19
+
20
+ def self.plurals
21
+ @plurals ||= [NOSOTROS, NOSOTRAS, VOSOTROS, VOSOTRAS, ELLOS, ELLAS, USTEDES]
22
+ end
23
+
24
+ def self.plural?(pro)
25
+ plurals.include?(pro)
26
+ end
27
+
28
+ def self.singulars
29
+ @singulars ||= [YO, TU, EL, ELLA, USTED]
30
+ end
31
+
32
+ def self.singular?(pro)
33
+ singulars.include?(pro)
34
+ end
35
+
36
+ def self.primera?(pro)
37
+ [YO, NOSOTROS, NOSOTRAS].include?(pro)
38
+ end
39
+
40
+ def self.segunda?(pro)
41
+ [TU, VOSOTROS, VOSOTRAS].include?(pro)
42
+ end
43
+
44
+ def self.tercera?(pro)
45
+ [El, ELLA, USTED, ELLOS, ELLAS, USTEDES].include?(pro)
46
+ end
47
+
48
+ def self.singular_primera?(pro)
49
+ pro == YO
50
+ end
51
+
52
+ def self.singular_segunda?(pro)
53
+ pro == TU
54
+ end
55
+
56
+ def self.singular_tercera?(pro)
57
+ [EL, ELLA, USTED].include?(pro)
58
+ end
59
+
60
+ def self.plural_primera?(pro)
61
+ [NOSOTROS, NOSOTRAS].include?(pro)
62
+ end
63
+
64
+ def self.plural_segunda?(pro)
65
+ [VOSOTROS, VOSOTRAS].include?(pro)
66
+ end
67
+
68
+ def self.plural_tercera?(pro)
69
+ [ELLOS, ELLAS, USTEDES].include?(pro)
70
+ end
71
+
72
+ def self.verbo_indice(pro)
73
+ metodos = [
74
+ :singular_primera?, :singular_segunda?, :singular_tercera?,
75
+ :plural_primera?, :plural_segunda?, :plural_tercera?
76
+ ]
77
+
78
+ metodos.find_index { |m| self.send(m, pro) }
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,14 @@
1
+ module Respanol
2
+ class Semana
3
+ DIAS = %w{
4
+ Domingo
5
+ Lunes
6
+ Martes
7
+ Miercoles
8
+ Jueves
9
+ Viernes
10
+ Sabado
11
+ Domingo
12
+ }
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ module Respanol
2
+ module Traducir
3
+ module ClassMethods
4
+ def definicion
5
+ nombre = self.name.split('::').last.downcase
6
+ @definicion ||= Traductor.traducir_y_definicion(nombre)
7
+
8
+ tpl = " | %s"
9
+ o = ["=> #{@definicion[:translated]}"]
10
+ o << " *---INGLÉS----------"
11
+ @definicion[:target_definitions].each do |d|
12
+ o << tpl % d
13
+ end
14
+ o << " *---ESPAÑOL----------"
15
+ @definicion[:source_definitions].each do |d|
16
+ o << tpl % d
17
+ end
18
+
19
+ puts o.join("\n")
20
+ end
21
+ end
22
+
23
+ module InstanceMethods
24
+
25
+ end
26
+
27
+ def self.included(receiver)
28
+ receiver.extend ClassMethods
29
+ receiver.send :include, InstanceMethods
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module Respanol
2
+ class Traductor
3
+ def self.traductor
4
+ @traductor ||= Glosbe::Translate.new('es', 'en')
5
+ end
6
+
7
+ def self.traducir(*args)
8
+ traductor.translate(*args)
9
+ end
10
+
11
+ def self.traducir_y_definicion(*args)
12
+ traductor.translate_and_definition(*args)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Aprender < VerboBase
4
+ CONJUGACION = %w{ aprendo aprendes aprende aprendemos aprendeis aprenden }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Caminar < VerboBase
4
+ CONJUGACION = %w{ camino caminas camina caminamos caminais caminan }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Dormir < VerboBase
4
+ CONJUGACION = %w{ duermo duermes duerme dormimos dormis duermen }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Entender < VerboBase
4
+ CONJUGACION = %w{ entiendo entiendes entiende entendemos entendeis entienden }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Hablar < VerboBase
4
+ CONJUGACION = %w{ hablo hablas habla hablamos hablais hablan }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Hacer < VerboBase
4
+ CONJUGACION = %w{ hago haces hace hacemos haceis hacen }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Jugar < VerboBase
4
+ CONJUGACION = %w{ juego juegas juega jugamos jugais juegan }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Leer < VerboBase
4
+ CONJUGACION = %w{ leo lees lee leemos leeis leen }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Poder < VerboBase
4
+ CONJUGACION = %w[ puedo puedes puede podemos podeis pueden ]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Ser < VerboBase
4
+ CONJUGACION = %w[ soy eres es somos sois son ]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Subir < VerboBase
4
+ CONJUGACION = %w{ subo subes sube subimos subis suben }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Tener < VerboBase
4
+ CONJUGACION = %w[ tengo tienes tiene tenemos teneis tienen ]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Tocar < VerboBase
4
+ CONJUGACION = %w{ toco tocas toca tocamos tocais tocan }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class VerboBase
4
+ CONJUGACION = []
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Viajar < VerboBase
4
+ CONJUGACION = %w{ viajo viajas viaja viajamos viajais viajan }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Respanol
2
+ module Verbo
3
+ class Vivir < VerboBase
4
+ CONJUGACION = %w{ vivo vives vive vivimos vivis viven }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Respanol
2
+ VERSION = "0.0.1"
3
+ end
data/lib/respanol.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'readline'
2
+ require 'glosbe'
3
+
4
+ require 'respanol/version'
5
+ require 'respanol/impresion'
6
+ require 'respanol/traducir'
7
+
8
+ require 'respanol/verbos/verbo_base'
9
+ require 'respanol/examenes/examen_base'
10
+
11
+ Dir['./lib/**/*.rb'].each { |file| require file }
data/respanol.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
+ require 'respanol/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'respanol'
7
+ s.version = Respanol::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.licenses = ['MIT']
10
+ s.authors = ['Drake Tran']
11
+ s.email = ['tievdrake@gmail.com']
12
+ s.summary = 'Makes learning Spanish fun and easy!'
13
+ s.description = 'Makes learning Spanish fun and easy! With all the core and tests'
14
+ s.homepage = 'https://github.com/tiev/respanol'
15
+
16
+
17
+ s.required_ruby_version = '>= 1.9.0'
18
+
19
+ s.add_runtime_dependency 'glosbe', '~> 0.0'
20
+ s.add_development_dependency 'guard', '~> 2.0'
21
+ s.add_development_dependency 'guard-bundler', '~> 2.0'
22
+ s.add_development_dependency 'guard-rspec', '~> 4.7'
23
+ s.add_development_dependency 'rspec', '~> 3.5'
24
+ s.add_development_dependency 'simplecov', '~> 0.14'
25
+
26
+ s.files = `git ls-files`.split("\n")
27
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
29
+ s.require_paths = ["lib"]
30
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.describe Respanol::Fecha do
2
+ describe '.fecha_en_palabras' do
3
+ it 'works' do
4
+ expect(Respanol::Fecha.fecha_en_palabras(Date.new(2001,1,1))).to eq('Lunes uno de Enero de dos mil uno')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ RSpec.describe Respanol::Hora do
2
+ describe '.comienzo' do
3
+ context 'when time at 1 hour' do
4
+ it { expect(Respanol::Hora.comienzo(Time.parse('1:0'))).to eq('Es la') }
5
+ end
6
+ context 'when time at more than 1:30' do
7
+ it { expect(Respanol::Hora.comienzo(Time.parse('1:31'))).to eq('Son las') }
8
+ end
9
+ end
10
+
11
+ describe '.hora_en_palabras' do
12
+ context 'at exact hour' do
13
+ it { expect(Respanol::Hora.hora_en_palabras(Time.parse('2:0'))).to include('en punto') }
14
+ end
15
+
16
+ context 'at a quarter' do
17
+ it { expect(Respanol::Hora.hora_en_palabras(Time.parse('2:15'))).to include('y cuarto') }
18
+ end
19
+
20
+ context 'at half hour' do
21
+ it { expect(Respanol::Hora.hora_en_palabras(Time.parse('2:30'))).to include('y media') }
22
+ end
23
+
24
+ context 'at minus hour' do
25
+ it { expect(Respanol::Hora.hora_en_palabras(Time.parse('2:31'))).to include('menos') }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ RSpec.describe Respanol::Impresion do
2
+ before :all do
3
+ Klase = Class.new.include(Respanol::Impresion)
4
+ Respanol::KlaseInterna = Class.new.include(Respanol::Impresion)
5
+ end
6
+
7
+ describe '.prefijo' do
8
+ it { expect { Klase.prefijo }.to output('Klase:: ').to_stdout }
9
+ it { expect { Respanol::KlaseInterna.prefijo }.to output('KlaseInterna:: ').to_stdout }
10
+ end
11
+
12
+ describe '.impresion' do
13
+ it { expect { Klase.impresion('test') }.to output('Klase:: test').to_stdout }
14
+ end
15
+ end
@@ -0,0 +1,99 @@
1
+ RSpec.describe Respanol::Numero do
2
+ describe '.numero_en_palabras' do
3
+ it 'works' do
4
+ expect(Respanol::Numero.numero_en_palabras(rand(100))).to be_instance_of(String)
5
+ end
6
+
7
+ context 'for number 0' do
8
+ it { expect(Respanol::Numero.numero_en_palabras(0)).to eq('cero') }
9
+ end
10
+ end
11
+
12
+ describe '.unirse_palabras' do
13
+ it 'accepts list of strings' do
14
+ expect(Respanol::Numero.unirse_palabras('a', 'b', 'c')).to eq('a b c')
15
+ end
16
+ end
17
+
18
+ describe '.unidad' do
19
+ context 'with 1 at end of number string' do
20
+ let(:object) { Respanol::Numero.unidad(1) }
21
+ it { expect(object).to eq('uno') }
22
+ end
23
+ context 'with 1 at middle of number string' do
24
+ let(:object) { Respanol::Numero.unidad(1, false) }
25
+ it { expect(object).to eq('un') }
26
+ end
27
+ end
28
+
29
+ describe '.tres_ultimos_en_palabras' do
30
+ context 'for number 100' do
31
+ let(:object) { Respanol::Numero.tres_ultimos_en_palabras(100) }
32
+ it { expect(object).to eq('cien') }
33
+ end
34
+ end
35
+
36
+ describe '.dos_ultimos_en_palabras' do
37
+ context 'for number 1..9' do
38
+ let(:object) {
39
+ (1..9).map { |v| Respanol::Numero.dos_ultimos_en_palabras(v) }
40
+ }
41
+ it {
42
+ expect(object).to satisfy('be correct') do |o|
43
+ o.map.with_index(1) do |v, i|
44
+ v == Respanol::Numero::UNIDADES[i]
45
+ end.all?
46
+ end
47
+ }
48
+ end
49
+
50
+ context 'for number 1x' do
51
+ let(:object) {
52
+ (11..19).map do |v|
53
+ Respanol::Numero.dos_ultimos_en_palabras(v)
54
+ end
55
+ }
56
+ it {
57
+ expect(object).to satisfy('be correct') do |o|
58
+ o.map.with_index(1) { |v, i| v == Respanol::Numero::DECENA[i] }.all?
59
+ end
60
+ }
61
+ end
62
+
63
+ context 'for number 2x' do
64
+ let(:object) {
65
+ (21..29).map do |v|
66
+ Respanol::Numero.dos_ultimos_en_palabras(v)
67
+ end
68
+ }
69
+ it { expect(object).to all(include('vienti')) }
70
+ end
71
+
72
+ context 'for numbers >= 3x' do
73
+ let(:object) { Respanol::Numero.dos_ultimos_en_palabras(32) }
74
+ it { expect(object).to include(' y ') }
75
+ end
76
+ end
77
+
78
+ describe '.feminino' do
79
+ it { expect(Respanol::Numero.feminino).to equal(Respanol::FemininoNumero) }
80
+ end
81
+ end
82
+
83
+ RSpec.describe Respanol::FemininoNumero do
84
+ describe '.unidad' do
85
+ context 'with 1' do
86
+ let(:object) { [Respanol::FemininoNumero.unidad(1), Respanol::FemininoNumero.unidad(1, false)] }
87
+ it { expect(object).to all(eq('una')) }
88
+ end
89
+ end
90
+
91
+ describe '.tres_ultimos_en_palabras' do
92
+ context 'with hundred numbers' do
93
+ let(:object) {
94
+ (200..900).step(100).map { |v| Respanol::FemininoNumero.tres_ultimos_en_palabras(v) }
95
+ }
96
+ it { expect(object).to all(end_with('ientas')) }
97
+ end
98
+ end
99
+ end
File without changes