= eventual * http://github.com/maca/eventual == DESCRIPCIÓN: Reconocimiento de fechas y periodos en lenguaje natural. Útil para crear interfaces de usuario basadas en texto. == SINOPSIS: El método event_parse del modulo Eventual reconoce y convierte una fecha o periodo expresado en lenguaje natural en objetos _Date_ o _DateTime_ Ejemplos: require 'rubygems' require 'eventual' Eventual.event_parse( 'del 5 al 7 de junio' ) => [#, #, #] Eventual.event_parse( 'del 5 al 7 de junio 2009', Date ) => [#, #, #] Eventual.event_parse( 'del 5 al 7 de junio del 2009 a las 16:00 y 18:00 horas' ){ |d| d.to_s } => ["2009-06-05T16:00:00+00:00", "2009-06-05T18:00:00+00:00", "2009-06-06T16:00:00+00:00", "2009-06-06T18:00:00+00:00", "2009-06-07T16:00:00+00:00", "2009-06-07T18:00:00+00:00"] Eventual.event_parse( 'del 5 al 7 de junio 2009' ){ |d| Eventual::WDAY_LIST[ d.wday ] } => ['viernes', 'sabado', 'domingo'] Ejemplos de formatos reconocidos: * 1 de enero * 21, 22 y 23 de enero del 2009 * 21, 22 y 23 de enero a las 20:00 horas * 21, 22 y 23 de enero a las 20:00 y 22:00 horas * viernes 1, sábado 2, domingo 3 y lunes 4 de enero del 2010 * martes y miércoles del 1 al 20 de junio del 2009 a las 16:00 y 18:00 horas * sábados y domingos del 1 de enero al 31 de diciembre del 2008 a las 16:00 * sábado y domingo del 1 de enero al 31 de diciembre * lunes a viernes del 1 de enero al 31 de diciembre del 2008 a las 16:00 * todos los sábados de diciembre del 2009 * lunes a viernes de enero a abril * del viernes 1 al domingo 3 de enero del 2010 Se puede extender _Date_ y _DateTime_ con Eventual requiriendo 'eventual/date_time' y 'eventual/date': require 'rubygems' require 'eventual' require 'eventual/date_time' require 'eventual/date' DateTime.event_parse( 'del 5 al 7 de junio' ) => [#, #, #] Date.event_parse( 'del 5 al 7 de junio 2009' ) => [#, #, #] Si se pasa un bloque se puede especificar si se desea usar el texto que sigue a la definición de fechas mediante pasando la opción _use_trailing_ => _true_: str = "1 de enero del 2009\nSede:El tercer lugar\n2 de enero del 2009\nSede:El tercer lugar" Eventual.event_parse( str, :use_trailing => true ) do |dia, texto_extra| [dia.to_s, texto_extra] end => [["2009-01-01T00:00:00+00:00", "Sede:El tercer lugar"], ["2009-01-02T00:00:00+00:00", "Sede:El tercer lugar"]] == TODO: * No estoy seguro de que Iconv funcione en windows, lo arreglaré pronto Formatos a reconocer * todos los lunes de junio * todo junio * domingos de septiembre * martes y miércoles de agosto * todo el año == INSTALACIÓN: sudo gem install maca-eventual -s http://gems.github.com == LICENCIA: (The MIT License) Copyright (c) 2009 Macario Ortega Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.