diter 0.1.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 +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +133 -0
- data/Rakefile +10 -0
- data/bin/diter +105 -0
- data/diter.gemspec +23 -0
- data/lib/diter.rb +1 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fd2031d5601d38b8ebe603946386068829d63add
|
4
|
+
data.tar.gz: 08fb06c2ebc08c37ff46e2eb5cd2eb8649ed973b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b81af6d3cdd5c12b8d7e9c21aa3a12f9aa11de022c3a4f897c7ddf944757d8d531005672f9f802ded5a90459e426aee7a29c7b534ff5bae5d3a3bb1d79d994d6
|
7
|
+
data.tar.gz: 145ab12dee8798b6bffd23b0e2b1bb5c65af8846a6571ed732808d6af2f34605c36b2d09cdeeb98e9b13fc01bf77a1852cead2364f22f5afa46fe8ef640d696b
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ojima.h@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Hikaru Ojima
|
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,133 @@
|
|
1
|
+
# Diter
|
2
|
+
|
3
|
+
`diter` is a date iteration command.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install diter
|
8
|
+
|
9
|
+
Or download the script:
|
10
|
+
|
11
|
+
$ curl https://raw.githubusercontent.com/ojima-h/diter/master/bin/diter > bin/diter
|
12
|
+
$ chmod +x bin/diter
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
*Basic usage:*
|
17
|
+
|
18
|
+
$ diter 2016-01-01 2016-01-03
|
19
|
+
2016-01-01
|
20
|
+
2016-01-02
|
21
|
+
2016-01-03
|
22
|
+
|
23
|
+
*Run command:*
|
24
|
+
|
25
|
+
$ diter 2016-01-01 2016-01-03 -- echo date={}
|
26
|
+
date=2016-01-01
|
27
|
+
date=2016-01-02
|
28
|
+
date=2016-01-03
|
29
|
+
|
30
|
+
*Reverse order:*
|
31
|
+
|
32
|
+
$ diter 2016-01-03 2016-01-01 -- echo date={}
|
33
|
+
date=2016-01-03
|
34
|
+
date=2016-01-02
|
35
|
+
date=2016-01-01
|
36
|
+
|
37
|
+
*Date format:*
|
38
|
+
|
39
|
+
$ diter 2016-01-01 2016-01-03 -F %Y/%m/%d
|
40
|
+
2016/01/01
|
41
|
+
2016/01/02
|
42
|
+
2016/01/03
|
43
|
+
|
44
|
+
*Date format in command:*
|
45
|
+
|
46
|
+
$ diter 2016-01-01 2016-01-03 -- echo date=%Y/%m/%d
|
47
|
+
date=2016/01/01
|
48
|
+
date=2016/01/02
|
49
|
+
date=2016/01/03
|
50
|
+
|
51
|
+
Refer to [Date#strftime](https://docs.ruby-lang.org/en/2.1.0/Date.html#method-i-strftime) for possible date formats.
|
52
|
+
|
53
|
+
*Parallel execution (with xargs):*
|
54
|
+
|
55
|
+
$ bin/diter 2016-01-01 2016-01-03 | xargs -I{} -P2 -t echo date={}
|
56
|
+
echo date=2016-01-01
|
57
|
+
echo date=2016-01-02
|
58
|
+
date=2016-01-01
|
59
|
+
date=2016-01-02
|
60
|
+
echo date=2016-01-03
|
61
|
+
date=2016-01-03
|
62
|
+
|
63
|
+
*Loop:*
|
64
|
+
|
65
|
+
$ for lang in en ja fr; do
|
66
|
+
> for date in `diter 2016-01-01 2016-01-03`; do
|
67
|
+
> echo lang=$lang date=$date
|
68
|
+
> done
|
69
|
+
> done
|
70
|
+
lang=en date=2016-01-01
|
71
|
+
lang=en date=2016-01-02
|
72
|
+
lang=en date=2016-01-03
|
73
|
+
lang=ja date=2016-01-01
|
74
|
+
lang=ja date=2016-01-02
|
75
|
+
lang=ja date=2016-01-03
|
76
|
+
lang=fr date=2016-01-01
|
77
|
+
lang=fr date=2016-01-02
|
78
|
+
lang=fr date=2016-01-03
|
79
|
+
|
80
|
+
*Filter by the day of week:*
|
81
|
+
|
82
|
+
$ diter 2016-01-01 2016-01-31 --wday=1
|
83
|
+
2016-01-04
|
84
|
+
2016-01-11
|
85
|
+
2016-01-18
|
86
|
+
2016-01-25
|
87
|
+
|
88
|
+
*Filter by the day of month:*
|
89
|
+
|
90
|
+
$ diter 2016-01-01 2016-04-01 --mday=15
|
91
|
+
2016-01-15
|
92
|
+
2016-02-15
|
93
|
+
2016-03-15
|
94
|
+
|
95
|
+
A negative integer is assumed to be relative to the end of month:
|
96
|
+
|
97
|
+
$ diter 2016-01-01 2016-04-01 --mday=-1
|
98
|
+
2016-01-31
|
99
|
+
2016-02-29
|
100
|
+
2016-03-31
|
101
|
+
|
102
|
+
*In a Ruby script:*
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
require 'diter'
|
106
|
+
|
107
|
+
from = Date.new(2016, 1, 1)
|
108
|
+
to = Date.new(2016, 1, 31)
|
109
|
+
|
110
|
+
Diter[from, to, wday: 3].each do |date|
|
111
|
+
puts date.strftime('%Y/%m/%d')
|
112
|
+
end
|
113
|
+
#=>
|
114
|
+
# 2016/01/06
|
115
|
+
# 2016/01/13
|
116
|
+
# 2016/01/20
|
117
|
+
# 2016/01/27
|
118
|
+
```
|
119
|
+
|
120
|
+
## Development
|
121
|
+
|
122
|
+
Run `rake test` to run the tests.
|
123
|
+
|
124
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
125
|
+
|
126
|
+
## Contributing
|
127
|
+
|
128
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ojima-h/diter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
129
|
+
|
130
|
+
|
131
|
+
## License
|
132
|
+
|
133
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/diter
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
class Diter
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
class << self
|
9
|
+
alias [] new
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(from, to, options = {})
|
13
|
+
@range = from < to ? from..to : (to..from).reverse_each
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def each
|
18
|
+
@range.each do |date|
|
19
|
+
next unless filter_wday(date)
|
20
|
+
next unless filter_mday(date)
|
21
|
+
|
22
|
+
yield date
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def filter_wday(date)
|
27
|
+
return true unless @options[:wday]
|
28
|
+
|
29
|
+
date.wday == @options[:wday]
|
30
|
+
end
|
31
|
+
|
32
|
+
def filter_mday(date)
|
33
|
+
return true unless @options[:mday]
|
34
|
+
|
35
|
+
if @options[:mday] > 0
|
36
|
+
date.mday == @options[:mday]
|
37
|
+
else
|
38
|
+
(date - @options[:mday]).mday == 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if __FILE__ == $0
|
44
|
+
require 'optparse'
|
45
|
+
|
46
|
+
def execute(program, *args)
|
47
|
+
Process.waitpid(spawn(program, *args))
|
48
|
+
$?.success?
|
49
|
+
rescue Errno::EACCES, Errno::ENOEXEC
|
50
|
+
$stderr.puts "diter: not executable: #{args.first}"
|
51
|
+
false
|
52
|
+
rescue Errno::ENOENT
|
53
|
+
$stderr.puts "diter: command not found: #{args.first}"
|
54
|
+
false
|
55
|
+
end
|
56
|
+
|
57
|
+
options = {
|
58
|
+
format: '%Y-%m-%d',
|
59
|
+
replace: '{}'
|
60
|
+
}
|
61
|
+
opt = OptionParser.new
|
62
|
+
opt.banner = <<-TEXT
|
63
|
+
diter [OPTIONS] FROM TO [COMMAND..]
|
64
|
+
TEXT
|
65
|
+
opt.on('-F', '--format FORMAT') { |v| options[:format] = v }
|
66
|
+
opt.on('-I', '--replace PLACEHOLDER') { |v| options[:replace] = v }
|
67
|
+
opt.on('-w', '--weekly') { options[:wday] = 1 }
|
68
|
+
opt.on('-W', '--wday WDAY') { |v| options[:wday] = v.to_i }
|
69
|
+
opt.on('-m', '--monthly') { options[:mday] = 1 }
|
70
|
+
opt.on('-M', '--mday MDAY') { |v| options[:mday] = v.to_i }
|
71
|
+
|
72
|
+
from, to, *args = opt.parse(ARGV)
|
73
|
+
|
74
|
+
if from.nil? || to.nil?
|
75
|
+
$stderr.puts opt.help
|
76
|
+
exit 1
|
77
|
+
end
|
78
|
+
|
79
|
+
begin
|
80
|
+
from_date = Date.parse(from)
|
81
|
+
to_date = Date.parse(to)
|
82
|
+
rescue ArgumentError
|
83
|
+
$stderr.puts 'Invalid date format'
|
84
|
+
exit 1
|
85
|
+
end
|
86
|
+
|
87
|
+
command = args.map { |c| c.gsub(options[:replace], options[:format]) }
|
88
|
+
|
89
|
+
errors = 0
|
90
|
+
Diter[from_date, to_date, options].each do |date|
|
91
|
+
if command.empty?
|
92
|
+
puts date.strftime(options[:format])
|
93
|
+
else
|
94
|
+
cmd = command.map { |c| date.strftime(c) }
|
95
|
+
result = execute(*cmd)
|
96
|
+
errors += 1 unless result
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
if errors > 0
|
101
|
+
$stderr.puts "\n"
|
102
|
+
$stderr.puts "diter: #{errors} commands failed"
|
103
|
+
exit 1
|
104
|
+
end
|
105
|
+
end
|
data/diter.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'diter'
|
5
|
+
spec.version = '0.1.0'
|
6
|
+
spec.authors = ['Hikaru Ojima']
|
7
|
+
spec.email = ['ojima.h@gmail.com']
|
8
|
+
|
9
|
+
spec.summary = 'Date iteration utility.'
|
10
|
+
spec.description = 'Date iteration utility.'
|
11
|
+
spec.homepage = 'https://github.com/ojima-h/diter'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
|
+
f.match(%r{^(test|spec|features)/})
|
16
|
+
end
|
17
|
+
spec.bindir = 'bin'
|
18
|
+
spec.executables = ['diter']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
23
|
+
end
|
data/lib/diter.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path('../../bin/diter', __FILE__)
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: diter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hikaru Ojima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-10 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.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: Date iteration utility.
|
56
|
+
email:
|
57
|
+
- ojima.h@gmail.com
|
58
|
+
executables:
|
59
|
+
- diter
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/diter
|
71
|
+
- diter.gemspec
|
72
|
+
- lib/diter.rb
|
73
|
+
homepage: https://github.com/ojima-h/diter
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.5.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Date iteration utility.
|
97
|
+
test_files: []
|