date_misc 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3378aa0d761383c6b3ae35c44a419d4d76760aa2
4
+ data.tar.gz: afa4a04894d11e50a6456187390c3ec37fa2e41a
5
+ SHA512:
6
+ metadata.gz: f79a390ce334eca53d1cdc3fef23c794e355e1c6fb603e117ce5f113cbce09b135328148a3b196370e33bb747a0a05e20bd1ee29825aa7b504d7f97d11b1d2b5
7
+ data.tar.gz: 48636567ad15958081eebcc8ba2f116438f6faf13f7e0e35da26343dd71e46005f5484f55ed2f0b4c4e444886a213f8fd54cc0d577b5bdf4f82c1bba29fc3396
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ /vendor/bundle/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.2.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 SHIOYA, Hiromu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # DateMisc
2
+
3
+ [![Build Status](https://travis-ci.org/kwappa/date_misc.svg?branch=master)](https://travis-ci.org/kwappa/date_misc)
4
+
5
+ add misc methods to `Date`
6
+
7
+ ## Usage
8
+
9
+ `require 'date_misc'`
10
+
11
+ - `Date.easy_parse(date_string)`
12
+ - 'tomorrow', 'today' and 'yesterday' returns as you imagined
13
+ - other string will be passed to original `Date.parse`
14
+ - if invalid string is given, returns `Date.today`
15
+ - `Date#wday_position`
16
+ - returns position of wday in current month
17
+ - e.g : 23, Jan 2016 is 4th Saturday of this month
18
+
19
+ ```
20
+ [1] pry(main)> Date.today
21
+ => #<Date: 2016-01-23 ((2457411j,0s,0n),+0s,2299161j)>
22
+ [2] pry(main)> Date.today.wday
23
+ => 6
24
+ [3] pry(main)> Date.today.wday_position
25
+ => 4
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/date_misc.
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ task default: :test
5
+
6
+ desc 'Run test_unit based test'
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'test'
9
+ t.test_files = Dir['test/**/test_*.rb']
10
+ t.verbose = true
11
+ end
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'date_misc'
5
+ require 'pry'
6
+
7
+ Pry.start
data/date_misc.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'date_misc/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'date_misc'
7
+ spec.version = DateMisc::VERSION
8
+ spec.authors = ['SHIOYA, Hiromu']
9
+ spec.email = ['kwappa.856@gmail.com']
10
+
11
+ spec.summary = 'add some convinient methods on Date'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/kwappa/date_misc'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.11'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'pry'
24
+ spec.add_development_dependency 'test-unit'
25
+ end
data/lib/date_misc.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'date_misc/version'
2
+ require 'date_misc/easy_parse'
3
+ require 'date_misc/wday_position'
4
+
5
+ class Date
6
+ extend ::DateMisc::EasyParse
7
+ include ::DateMisc::WdayPosition
8
+ end
@@ -0,0 +1,19 @@
1
+ module DateMisc
2
+ module EasyParse
3
+ def easy_parse(date_str)
4
+ date_str = date_str.strip.downcase
5
+ case date_str
6
+ when 'today'
7
+ Date.today
8
+ when 'tomorrow'
9
+ Date.today + 1
10
+ when 'yesterday'
11
+ Date.today - 1
12
+ else
13
+ Date.parse(date)
14
+ end
15
+ rescue
16
+ Date.today
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module DateMisc
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,7 @@
1
+ module DateMisc
2
+ module WdayPosition
3
+ def wday_position
4
+ (self.day - 1) / 7 + 1
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: date_misc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - SHIOYA, Hiromu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-23 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
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
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: add some convinient methods on Date
70
+ email:
71
+ - kwappa.856@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - date_misc.gemspec
84
+ - lib/date_misc.rb
85
+ - lib/date_misc/easy_parse.rb
86
+ - lib/date_misc/version.rb
87
+ - lib/date_misc/wday_position.rb
88
+ homepage: https://github.com/kwappa/date_misc
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.5.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: add some convinient methods on Date
112
+ test_files: []