international_date_parser 0.2.4 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e37a3e7aab1142910ddd5e4ff07b1aef159fe730
4
- data.tar.gz: 1a26b5b98d35d841dce3909f5260d9e26d1c13be
2
+ SHA256:
3
+ metadata.gz: 4aea5c16300e428035b8f94e7dda37120ce53af69200218a8eca17c110835180
4
+ data.tar.gz: 443cc512708408fcb842225e2b0d60497a654ce31ab0478d36c0a140728579e2
5
5
  SHA512:
6
- metadata.gz: 5aa3bd7f6cab479fc57fee615e109adf165361aa7db4c82153fd0a6d28caf8fd7356a06642bd92b1e9b1c4f02deca04bc0d5f929fb0e127f023a02f7818b6594
7
- data.tar.gz: a280295386eaabf405eb8756226a344f3e0b4c31a48abdfbe255068222c285b14ee721a6471af96c7819c82f9d870209d6d7e332cb4ce4cb110f02e43b8c79e4
6
+ metadata.gz: 839f83afa5b387821b817d77504335789480f68e948be723bba3caa3ba035cd8ac997e1bf42d2b40abd71ad98bb6415ff4879f0009ffd4412f3c40e1f16a7a3e
7
+ data.tar.gz: 73cfdb83d239e3492e362ee2ac8ef19cfa60743b5b9aaa7895b74f8baabf48efe456062c435f9080675b1f9105f8ae8a7acbe89f2544123a9ef9cc187b8782b4
data/Gemfile CHANGED
@@ -1,4 +1,23 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in international_date_parser.gemspec
4
+
4
5
  gemspec
6
+
7
+ gem 'rspec'
8
+ gem 'guard-rspec'
9
+
10
+ # require 'lib/internation_date_parser/version'
11
+
12
+ Gem::Specification.new do |s|
13
+ s.name = 'example'
14
+ s.version = '0.3.0'
15
+ s.licenses = ['MIT']
16
+ s.summary = "parse string and arrays to date"
17
+ s.description = "Parse string or array that are in some languages to date"
18
+ s.authors = ["Humbero Pinto"]
19
+ s.email = 'hls.p999@gmail.com'
20
+ s.files = ["lib/international_date_parser.rb"]
21
+ s.homepage = 'https://rubygems.org/gems/international_date_parser'
22
+ # s.metadata = { "source_code_uri" => "https://github.com/example/example" }
23
+ end
@@ -0,0 +1,46 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+
19
+ # Note: The cmd option is now required due to the increasing number of ways
20
+ # rspec may be run, below are examples of the most common uses.
21
+ # * bundler: 'bundle exec rspec'
22
+ # * bundler binstubs: 'bin/rspec'
23
+ # * spring: 'bin/rspec' (This will use spring if running and you have
24
+ # installed the spring binstubs per the docs)
25
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
26
+ # * 'just' rspec: 'rspec'
27
+
28
+ guard :rspec, cmd: "bundle exec rspec" do
29
+ require "guard/rspec/dsl"
30
+ dsl = Guard::RSpec::Dsl.new(self)
31
+
32
+ # Feel free to open issues for suggestions and improvements
33
+
34
+ # RSpec files
35
+ rspec = dsl.rspec
36
+ watch(rspec.spec_helper) { rspec.spec_dir }
37
+ watch(rspec.spec_support) { rspec.spec_dir }
38
+ watch(rspec.spec_files)
39
+
40
+ # Ruby files
41
+ ruby = dsl.ruby
42
+ dsl.watch_spec_files_for(ruby.lib_files)
43
+
44
+
45
+
46
+ end
@@ -26,15 +26,25 @@ module InternationalDateParser
26
26
  it: %w(gennaio febbraio marzo aprile maggio giugno luglio agosto settembre ottobre novembre dicembre), # Italian
27
27
  es: %w(enero febrero marzo abril mayo junio julio agosto septiembre octubre noviembre diciembre), # Spanish
28
28
  pt: %w(janeiro fevereiro março abril maio junho julho agosto setembro outubro novembro dezembro), # Portuguese
29
+ en: Date::MONTHNAMES[1..12], # English
29
30
  }
30
31
  MONTH_TRANSLATIONS = MONTH_TO_PARSE.values.flatten
31
32
  MONTH_TRANSLATIONS_SHORT = MONTH_TRANSLATIONS.map{|m| m[0,3]}
32
33
 
33
34
  def self.parse_international(date)
34
- Date.parse(date_to_english(date))
35
+ return nil if date.nil? || date.empty?
36
+ if date.is_a? Array
37
+ date.push(Date.today.year) if date.flatten.count <= 2
38
+ date = date.join(" ")
39
+ end
40
+ if date.scan(/[a-zA-Z]/).empty?
41
+ Date.parse(date)
42
+ else
43
+ Date.parse(date_to_english(date))
44
+ end
35
45
  end
36
46
 
37
- def self.date_to_english(date)
47
+ def self.date_to_english(date)
38
48
  month_from = date[/[^\s\d,]{3,}/i].downcase # Search for a month name
39
49
  month_index = MONTH_TRANSLATIONS.index(month_from) || MONTH_TRANSLATIONS_SHORT.index(month_from)
40
50
  date.scan(/\s[^\s\d,]{1,2}\s/).each{|s| date.sub!(s[/[^\s]+/],'') if s}
@@ -1,6 +1,6 @@
1
1
  module InternationalDateParser
2
2
  MAJOR = 0
3
- MINOR = 2
4
- REVISION = 4
3
+ MINOR = 3
4
+ REVISION = 0
5
5
  VERSION = [MAJOR, MINOR, REVISION].join(".")
6
6
  end
@@ -0,0 +1,57 @@
1
+ require 'international_date_parser'
2
+ RSpec.describe InternationalDateParser do
3
+ context 'class methods' do
4
+ describe 'international_date_parser' do
5
+ let :idp do
6
+ InternationalDateParser::Date
7
+ end
8
+ it 'is nil when input date is nil or empty' do
9
+ expect(idp.parse_international(nil)).to be nil
10
+ expect(idp.parse_international([])).to be nil
11
+ end
12
+ describe 'given a date without words' do
13
+ it 'returns a date if Ymd is given' do
14
+ expect(idp.parse_international('2011-01-01')).to eq Date.new(2011,01,01)
15
+ end
16
+ it 'returns a date if dmY is given' do
17
+ expect(idp.parse_international('01-01-2011')).to eq Date.new(2011,01,01)
18
+ end
19
+ it 'returns a date if ymd is given' do
20
+ expect(idp.parse_international('11-01-01')).to eq Date.new(2011,01,01)
21
+ end
22
+ end
23
+ describe 'given a date in english' do
24
+ it 'returns a date' do
25
+ expect(idp.parse_international('2011 January 01')).to eq Date.new(2011,01,01)
26
+ expect(idp.parse_international('2011 Jan 01')).to eq Date.new(2011,01,01)
27
+ expect(idp.parse_international('01 January 2011')).to eq Date.new(2011,01,01)
28
+ expect(idp.parse_international('01 Jan 2011')).to eq Date.new(2011,01,01)
29
+ end
30
+ end
31
+ describe 'given a date in portuguese' do
32
+ it 'returns a date' do
33
+ expect(idp.parse_international('2011 Fevereiro 01')).to eq Date.new(2011,02,01)
34
+ expect(idp.parse_international('2011 Fev 01')).to eq Date.new(2011,02,01)
35
+ expect(idp.parse_international('01 Fevereiro 2011')).to eq Date.new(2011,02,01)
36
+ expect(idp.parse_international('01 Fev 2011')).to eq Date.new(2011,02,01)
37
+ end
38
+ end
39
+ describe 'given a date without the year' do
40
+ it 'returns a date' do
41
+ expect(idp.parse_international('Fevereiro 01')).to eq Date.new(2018,02,01)
42
+ expect(idp.parse_international('Fev 01')).to eq Date.new(2018,02,01)
43
+ expect(idp.parse_international('01 Fevereiro')).to eq Date.new(2018,02,01)
44
+ expect(idp.parse_international('01 Fev')).to eq Date.new(2018,02,01)
45
+ end
46
+ end
47
+ describe 'given a date in array' do
48
+ it 'returns a date' do
49
+ expect(idp.parse_international(['Fevereiro 01'])).to eq Date.new(2018,02,01)
50
+ expect(idp.parse_international([[01],['Fev']])).to eq Date.new(2018,02,01)
51
+ expect(idp.parse_international([['Fev'],['01']])).to eq Date.new(2018,02,01)
52
+ expect(idp.parse_international([['Fev'],['01'],[2011]])).to eq Date.new(2011,02,01)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: international_date_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Humberto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-02 00:00:00.000000000 Z
11
+ date: 2018-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - Gemfile
64
+ - Guardfile
64
65
  - LICENSE.txt
65
66
  - README.md
66
67
  - Rakefile
@@ -68,6 +69,7 @@ files:
68
69
  - lib/international_date_parser.rb
69
70
  - lib/international_date_parser/railtie.rb
70
71
  - lib/international_date_parser/version.rb
72
+ - spec/lib/international_date_parser_spec.rb
71
73
  homepage: http://github.com/frenesim/international_date_parser
72
74
  licenses:
73
75
  - MIT
@@ -88,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
90
  version: '0'
89
91
  requirements: []
90
92
  rubyforge_project:
91
- rubygems_version: 2.5.1
93
+ rubygems_version: 2.7.7
92
94
  signing_key:
93
95
  specification_version: 4
94
96
  summary: International Date Parser