diter 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32f5194dbd92a4f0455a122b7d26dbae4fae3d4f
4
- data.tar.gz: 20708f0e49773f0ea8dbf769ebcb78850c8a8ab0
3
+ metadata.gz: 94747650af6e626f711d0341f35f3125ae5fec03
4
+ data.tar.gz: 35317fe2907e045be258f308e3a9dab624aeb6cd
5
5
  SHA512:
6
- metadata.gz: b1484c8a3bbf56cd1fcb08578aa348bb6ac811c803eb9436582b9944b056c081c4d6a88a05cef9c4d2a30c665d727a24481cd2ef4403061057d2bdef92602df6
7
- data.tar.gz: 2c8e03b8237eee47c4c933172fea171062e6c65a8a277a9c7bc0921385e2d41d99705b54807255936131c755352b3feebc15b0ab8a9c513ebfdd73ff2eda9911
6
+ metadata.gz: ce80f11fff16d7e4be457c58c36c09adbae888c1c3ac694eaed00682c8b927612e4664a5b94f78e4373c07121dcf8827c2a00a70504df615c6cf496db3c45f99
7
+ data.tar.gz: d77d4b939d3a87d89ed4bcacad41f8cc348e1fcfb87dd11a1b0254f36f4e7e1a5af922f1a6252a0564e21a961ad366a31e88d699557d3dee76f93a8d986a9a44
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ -m markdown bin/*
data/README.md CHANGED
@@ -52,7 +52,7 @@ Refer to [Date#strftime](https://docs.ruby-lang.org/en/2.1.0/Date.html#method-i-
52
52
 
53
53
  *Parallel execution (with xargs):*
54
54
 
55
- $ bin/diter 2016-01-01 2016-01-03 | xargs -I{} -P2 -t echo date={}
55
+ $ diter 2016-01-01 2016-01-03 | xargs -I{} -P2 -t echo date={}
56
56
  echo date=2016-01-01
57
57
  echo date=2016-01-02
58
58
  date=2016-01-01
data/bin/diter CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  require 'date'
4
4
 
5
+ # `Diter` enumerate dates with some filters.
6
+ #
7
+ # require 'diter'
8
+ #
9
+ # from = Date.new(2016, 1, 1)
10
+ # to = Date.new(2016, 1, 31)
11
+ #
12
+ # Diter[from, to, wday: 3].each do |date|
13
+ # puts date.strftime('%Y/%m/%d')
14
+ # end
15
+ # #=>
16
+ # # 2016/01/06
17
+ # # 2016/01/13
18
+ # # 2016/01/20
19
+ # # 2016/01/27
20
+ #
5
21
  class Diter
6
22
  include Enumerable
7
23
 
@@ -9,12 +25,30 @@ class Diter
9
25
  alias [] new
10
26
  end
11
27
 
28
+ # Return a new instance of `Diter`.
29
+ #
30
+ # If `from` is greater than `to`, it enumerate dates in reverse order.
31
+ #
32
+ # @param [Date] from the start of dates
33
+ # @param [Date] to the end of dates
34
+ # @param [Hash] options
35
+ # @option options [Integer] :wday (nil) filter by the day of a week.
36
+ # @option options [Integer] :mday (nil) filter by the day of a month.
37
+ # @return [Diter]
12
38
  def initialize(from, to, options = {})
13
39
  @range = from < to ? from..to : (to..from).reverse_each
14
40
  @options = options
15
41
  end
16
42
 
43
+ # Calls the given block once for each date.
44
+ #
45
+ # Return `self` if no block is given.
46
+ #
47
+ # @yieldparam date [Date]
48
+ # @return [Diter] self
17
49
  def each
50
+ return self unless block_given?
51
+
18
52
  @range.each do |date|
19
53
  next unless filter_wday(date)
20
54
  next unless filter_mday(date)
@@ -23,6 +57,8 @@ class Diter
23
57
  end
24
58
  end
25
59
 
60
+ private
61
+
26
62
  def filter_wday(date)
27
63
  return true unless @options[:wday]
28
64
 
@@ -47,10 +83,10 @@ unless $DITER_REQUIRED # $DITER_REQUIRED is set to true in lib/diter.rb
47
83
  Process.waitpid(spawn(program, *args))
48
84
  $?.success?
49
85
  rescue Errno::EACCES, Errno::ENOEXEC
50
- $stderr.puts "diter: not executable: #{args.first}"
86
+ $stderr.puts "diter: not executable: #{program}"
51
87
  false
52
88
  rescue Errno::ENOENT
53
- $stderr.puts "diter: command not found: #{args.first}"
89
+ $stderr.puts "diter: command not found: #{program}"
54
90
  false
55
91
  end
56
92
 
data/diter.gemspec CHANGED
@@ -1,10 +1,14 @@
1
1
  # coding: utf-8
2
2
 
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'diter/version'
6
+
3
7
  Gem::Specification.new do |spec|
4
8
  spec.name = 'diter'
5
- spec.version = '0.1.1'
9
+ spec.version = Diter::VERSION
6
10
  spec.authors = ['Hikaru Ojima']
7
- spec.email = ['ojima.h@gmail.com']
11
+ spec.email = ['amijo4rihaku@gmail.com']
8
12
 
9
13
  spec.summary = 'Date iteration utility.'
10
14
  spec.description = 'Date iteration utility.'
@@ -20,4 +24,5 @@ Gem::Specification.new do |spec|
20
24
  spec.add_development_dependency 'bundler', '~> 1.13'
21
25
  spec.add_development_dependency 'rake', '~> 10.0'
22
26
  spec.add_development_dependency 'minitest', '~> 5.0'
27
+ spec.add_development_dependency 'yard', '~> 0.9'
23
28
  end
@@ -0,0 +1,3 @@
1
+ class Diter
2
+ VERSION = '0.1.2'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hikaru Ojima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-10 00:00:00.000000000 Z
11
+ date: 2016-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,9 +52,23 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
55
69
  description: Date iteration utility.
56
70
  email:
57
- - ojima.h@gmail.com
71
+ - amijo4rihaku@gmail.com
58
72
  executables:
59
73
  - diter
60
74
  extensions: []
@@ -62,6 +76,7 @@ extra_rdoc_files: []
62
76
  files:
63
77
  - ".gitignore"
64
78
  - ".travis.yml"
79
+ - ".yardopts"
65
80
  - CODE_OF_CONDUCT.md
66
81
  - Gemfile
67
82
  - LICENSE.txt
@@ -70,6 +85,7 @@ files:
70
85
  - bin/diter
71
86
  - diter.gemspec
72
87
  - lib/diter.rb
88
+ - lib/diter/version.rb
73
89
  homepage: https://github.com/ojima-h/diter
74
90
  licenses:
75
91
  - MIT