cyymmdd_converter 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e6b6c839f056b5f0a10e3f94270f943fb1d35bc
4
+ data.tar.gz: 64f69044d5e7a94d802f491503985d71a93c6f64
5
+ SHA512:
6
+ metadata.gz: 08b60b7eaef6edcad5536917c1f7f33e3f125a4c205247d5eeaabfed88f54b8d6642b902d3ad20ad5d2bfad7d8eec78f24b14b8c4810212b0e6cf7758a99bf33
7
+ data.tar.gz: f49de2f71fc56d2e52ddfc3b417c8822a6292f3d487df55d51466e821ddb0d6f08aff1b8013dc121f557630db98222ce76efce3cdffa2661958a888279f9e869
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ .idea/*
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cyymmdd_converter.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Den
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # CyymmddConverter
2
+
3
+ With this awesome gem you can convert your cymmdd strings to Ruby Date object and back
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cyymmdd_converter', github: 'meliborn/cyymmdd_converter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cyymmdd_converter
18
+
19
+ ## Usage
20
+
21
+ '0980615'.convert_from_cyymmdd will produce Ruby Date object
22
+
23
+ Date.parse('1998-06-15').convert_to_cyymmdd will produce string '0980615
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/cyymmdd_converter/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cyymmdd_converter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cyymmdd_converter"
8
+ spec.version = CyymmddConverter::VERSION
9
+ spec.authors = ["Meliborn"]
10
+ spec.email = ["denthebat@gmail.com"]
11
+ spec.summary = %q{Two-way CYYMMDD converter}
12
+ spec.description = %q{With this gem you could simply convert string to cyymmdd format and back}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'rspec'
24
+ end
@@ -0,0 +1,43 @@
1
+ require 'cyymmdd_converter/version'
2
+
3
+ module CyymmddConverter
4
+ String.class_eval do
5
+ def convert_from_cyymmdd
6
+ cleared_string = self
7
+
8
+ # Pass missing zero\one to the beginning
9
+ unless self['.'].nil?
10
+ temp = self.split('.')
11
+ cleared_string = temp.reverse.join if temp.last == '0' && temp.first.length == 6
12
+ end
13
+ cleared_string = cleared_string.split('.').first
14
+
15
+ # Validate input date, return false if didn't pass
16
+ return false unless cleared_string =~ /\A[1|0]{1}(0[1-9]|[10-99]){1,2}(0[1-9]|1[0-2]){1}(0[1-9]|1[0-9]|2[0-9]|3[0-2]){1}\z/
17
+
18
+ # Remove first digit (century)
19
+ begin
20
+ converted_date = Date.parse cleared_string.slice(1..-1)
21
+ rescue Exception => e
22
+ return false
23
+ end
24
+
25
+ # Subsctract 100 years if we've got something after 2000 year, but century mark was zero
26
+ converted_date = converted_date - 100.years if cleared_string[0] == '0' && converted_date.year >= 2000
27
+
28
+ # Return converted date
29
+ converted_date
30
+ end
31
+ end
32
+
33
+ Date.class_eval do
34
+ def convert_to_cyymmdd
35
+ converted_date = self.strftime('%y%m%d')
36
+
37
+ # calculate century
38
+ century = self.year >= 2000 ? 1 : 0
39
+
40
+ "#{century.to_s}#{converted_date}"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module CyymmddConverter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe CyymmddConverter do
4
+ describe 'String' do
5
+ it 'should convert cyymmdd date to Ruby Date object' do
6
+ expect('0980615'.convert_from_cyymmdd).to eq(Date.parse('1998-06-15'))
7
+ expect('950101.0'.convert_from_cyymmdd).to eq(Date.parse('1995-01-01'))
8
+ expect('1160509.0'.convert_from_cyymmdd).to eq(Date.parse('2016-05-09'))
9
+ expect('0.0'.convert_from_cyymmdd).to eq(false)
10
+ expect('1981313'.convert_from_cyymmdd).to eq(false)
11
+ expect('1150229'.convert_from_cyymmdd).to eq(false)
12
+ end
13
+ end
14
+
15
+ describe 'Date' do
16
+ it 'should convert Ruby Date objectto cyymmdd format' do
17
+ expect(Date.parse('1998-06-15').convert_to_cyymmdd).to eq('0980615')
18
+ end
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ require 'cyymmdd_converter'
@@ -0,0 +1,3 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cyymmdd_converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Meliborn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: With this gem you could simply convert string to cyymmdd format and back
56
+ email:
57
+ - denthebat@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".idea/.name"
64
+ - ".idea/.rakeTasks"
65
+ - ".idea/cyymmdd_converter.iml"
66
+ - ".idea/encodings.xml"
67
+ - ".idea/inspectionProfiles/Project_Default.xml"
68
+ - ".idea/inspectionProfiles/profiles_settings.xml"
69
+ - ".idea/misc.xml"
70
+ - ".idea/modules.xml"
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - cyymmdd_converter.gemspec
76
+ - lib/cyymmdd_converter.rb
77
+ - lib/cyymmdd_converter/version.rb
78
+ - spec/cyymmdd_converter_spec.rb
79
+ - spec/spec_helper.rb
80
+ - tasks/rspec.rake
81
+ homepage: ''
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.2.2
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Two-way CYYMMDD converter
105
+ test_files:
106
+ - spec/cyymmdd_converter_spec.rb
107
+ - spec/spec_helper.rb