international_date_parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 74e934932da95c151ea66f3be65a763378e610a2
4
+ data.tar.gz: 91dc9693ae2f4a24cc608dd60f3649fa565383e9
5
+ SHA512:
6
+ metadata.gz: 5de7f240b13e30208a2c458f810f3982857bebcd0b7f0583432138ced876486024b7249b79dece4c162c12adcb828e6865474f93e8bbb664365aac6dd36f1c89
7
+ data.tar.gz: 1bea74c8eaba6ea15cc8ecdf5f33c51df74a6b12518319a8bdd7dcb784453ad35da9a4b7fde36faa9ced00d68f183ed2fb1016bf206711e5ad596319a7df6787
@@ -0,0 +1,53 @@
1
+ module InternationalDateParser
2
+
3
+ # -*- coding: utf-8 -*-
4
+ #
5
+ # Purpose:
6
+ # Extend the date parsing capabilities of Ruby to work with dates with international month names.
7
+ #
8
+ # Usage:
9
+ #
10
+ # Date.parse_international(date_string)
11
+ # DateTime.parse_international(date_string)
12
+ # date_string.to_international_date
13
+ #
14
+ # Notes:
15
+ # 1) This routine works by substituting your local month names (as defined by Date::MONTHNAMES) for the
16
+ # international names when they occur in the date_string.
17
+ # 2) As distributed, this code works for French, German, Italian, and Spanish. You must add the month
18
+ # names for any additional languages you wish to handle.
19
+ #
20
+ class Date
21
+ def self.parse_international(date)
22
+ parse(date_to_english(date))
23
+ end
24
+
25
+ MONTH_TRANSLATIONS = []
26
+ MONTH_TRANSLATIONS += %w(janvier février mars avril mai juin juillet août septembre octobre novembre décembre) # French
27
+ MONTH_TRANSLATIONS += %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember) # German
28
+ MONTH_TRANSLATIONS += %w(gennaio febbraio marzo aprile maggio giugno luglio agosto settembre ottobre novembre dicembre) # Italian
29
+ MONTH_TRANSLATIONS += %w(enero febrero marzo abril mayo junio julio agosto septiembre octubre noviembre diciembre) # Spanish
30
+ MONTH_TRANSLATIONS += %w(janeiro fevereiro março abril maio junho julho agosto setembro outubro novembro dezembro) # Portuguese
31
+
32
+ MONTH_TRANSLATIONS_SHORT = MONTH_TRANSLATIONS.map{|m| m[0,3]}
33
+
34
+ def self.date_to_english(date)
35
+ month_from = date[/[^\s\d,]{3,}/i] # Search for a month name
36
+ month_number =(MONTH_TRANSLATIONS.index(month_from) || MONTH_TRANSLATIONS_SHORT.index(month_from))
37
+ date.sub(month_from, Date::MONTHNAMES[month_number % 12 + 1]) if month_number
38
+ end
39
+ end
40
+
41
+ class DateTime
42
+ def self.parse_international(string)
43
+ parse Date.date_to_english(string)
44
+ end
45
+ end
46
+
47
+ class String
48
+ def to_international_date
49
+ Date::parse_international(self).to_date
50
+ end
51
+ end
52
+
53
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,6 @@
1
+ module InternationalDateParser
2
+ MAJOR = 0
3
+ MINOR = 1
4
+ REVISION = 0
5
+ VERSION = [MAJOR, MINOR, REVISION].join(".")
6
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: international_date_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Frenesim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby class Date wrapper to translate months and then parse the string
14
+ email: hlsp999@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/international_date_parser.rb
20
+ - lib/version.rb
21
+ homepage: http://github.com/frenesim/international_date_parser
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.9.3
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: International Date Parser
45
+ test_files: []