require_date 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab8d0b09de2cc351489fc68545644a76ddcf9393
4
+ data.tar.gz: e429ea597ffffb55155ecd10f4fc2b34906880f2
5
+ SHA512:
6
+ metadata.gz: 2e7a54736792ee61227bd2b21fc80f5d4e49bd55a287b5a47bf4403d411145aa77119887e077a15938b9ce2a0f95ab3e6233547b46869465a851be4a1a1a2cef
7
+ data.tar.gz: 51f8945d6b765bb1b6f98b4556c9999387e0af6c0a8a70a515a4bcd0c84d36be3b16ac87a05a4745bf620602252c97dc930e843977bee13acd4921871af8d001
data/.gitignore ADDED
@@ -0,0 +1,30 @@
1
+ *.db
2
+ .DS_Store
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ /.yardoc/
15
+ /_yardoc/
16
+ /doc/
17
+ /rdoc/
18
+
19
+ /.bundle/
20
+ /lib/bundler/man/
21
+
22
+ Gemfile.lock
23
+ .ruby-version
24
+ .ruby-gemset
25
+
26
+ .rvmrc
27
+
28
+ *~
29
+ \#*\#
30
+ .\#*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ ruby '1.8.7'
3
+
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Keith Thibodeaux
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,63 @@
1
+ # require_date
2
+
3
+ Easily require date arguments for command line apps. Includes some
4
+ formats by default but can have custom regexp set. Pass a block to
5
+ override raising an argument error if the fetch fails.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'require_date'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install 'require_date'
20
+
21
+ ## Usage
22
+
23
+ $ ruby run.rb 20140101 20141212 2014-01
24
+
25
+
26
+ ```ruby
27
+ require 'rubygems' # Needed if using Ruby 1.8.7
28
+ require 'lib/require_date'
29
+
30
+ # Default RegExp is RequireDate.FORMATS[:date]
31
+ # The following hash is equal to RequireDate.FORMATS
32
+ # {
33
+ # :date => Regexp.union(/\A(\d{4})-(\d{2})-(\d{2})\z/, /\A(\d{4})(\d{2})(\d{2})\z/),
34
+ # :month_group => Regexp.union(/\A(\d{4})-(\d{2})\z/, /\A(\d{4})(\d{2})\z/)
35
+ # }
36
+
37
+ # Pull the first argument that matches the default RegExp
38
+ # Will raise an Argument error if nothing is foun
39
+ @start = RequireDate.try_parse(RequireDate.next)
40
+
41
+ # Pull the next argument that matches the default RegExp
42
+ # The block overrides the raise and sets the value to today
43
+ @end = RequireDate.try_parse(RequireDate.next { @start + 1 })
44
+
45
+ # Pull the next argument that matches the given RegExp
46
+ # We do not run this through RequireDate.try_parse since it isn't
47
+ # a complete date, just a reference point we can use
48
+ @month_group = RequireDate.next(RequireDate::FORMATS[:month_group])
49
+
50
+ # Results
51
+ @start # => #<Date: 4913317/2,0,2299161>
52
+ @end # => #<Date: 4914007/2,0,2299161>
53
+ @month_group # => "2014-01"
54
+ ```
55
+
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/kthibodeaux/require_date/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
@@ -0,0 +1,35 @@
1
+ require 'date'
2
+
3
+ module RequireDate
4
+
5
+ VERSION = '0.0.1'
6
+
7
+ ARGUMENT_LIST = ARGV
8
+
9
+ FORMATS = {
10
+ :date => Regexp.union(/\A(\d{4})-(\d{2})-(\d{2})\z/, /\A(\d{4})(\d{2})(\d{2})\z/),
11
+ :month_group => Regexp.union(/\A(\d{4})-(\d{2})\z/, /\A(\d{4})(\d{2})\z/)
12
+ }
13
+
14
+ def self.next(format = FORMATS[:date], &block)
15
+ ARGUMENT_LIST.each_with_index do |x, i|
16
+ if x[format]
17
+ return_value = x
18
+ ARGUMENT_LIST.delete_at(i)
19
+ return return_value
20
+ end
21
+ end
22
+
23
+ if block_given?
24
+ yield block
25
+ else
26
+ raise ArgumentError, "No day remaining to pull from ARGV"
27
+ end
28
+ end
29
+
30
+ def self.try_parse(date)
31
+ return date if Date === date
32
+ return Date.parse(date)
33
+ end
34
+
35
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'require_date'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'require_date'
8
+ spec.version = RequireDate::VERSION
9
+ spec.authors = ["Keith Thibodeaux"]
10
+ spec.email = ["keith@railscoder.net"]
11
+ spec.summary = 'Easily require date arguments'
12
+ spec.description = 'Easily require date arguments for command line apps. Includes some formats by default but can have custom regexp set. Pass a block to override raising an argument error if the fetch fails.'
13
+ spec.homepage = 'https://github.com/kthibodeaux/require_date'
14
+ spec.licenses = ['MIT']
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.test_files = spec.files.grep(%r{^(spec)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec", "~> 2.6"
23
+ end
@@ -0,0 +1,39 @@
1
+ require 'require_date'
2
+
3
+ describe RequireDate do
4
+
5
+ let(:date_format) { RequireDate::FORMATS[:date] }
6
+ let(:month_format) { RequireDate::FORMATS[:month_group] }
7
+
8
+ ARGV[0] = '2014-05-05'
9
+ ARGV[1] = '20140507'
10
+ ARGV[2] = '2014-02'
11
+
12
+ it 'raises an error when trying to pull an no argument matches format' do
13
+ expect { RequireDate.next(/\A\z/) }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ it 'pulls the first date' do
17
+ return_value = RequireDate.next(date_format)
18
+ expect(return_value).to eq('2014-05-05')
19
+ end
20
+
21
+ it 'pulls the second date' do
22
+ return_value = RequireDate.next(date_format)
23
+ expect(return_value).to eq('20140507')
24
+ end
25
+
26
+ it 'raises an error when trying to pull a third date' do
27
+ expect { @start_day = RequireDate.next(date_format) }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it 'pulls the third date' do
31
+ return_value = RequireDate.next(month_format)
32
+ expect(return_value).to eq('2014-02')
33
+ end
34
+
35
+ it 'raises an error when trying to pull a second month group' do
36
+ expect { @start_day = RequireDate.next(month_format) }.to raise_error(ArgumentError)
37
+ end
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: require_date
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Keith Thibodeaux
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2014-06-19 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: "1.6"
22
+ type: :development
23
+ version_requirements: *id001
24
+ - !ruby/object:Gem::Dependency
25
+ name: rake
26
+ prerelease: false
27
+ requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - &id004
30
+ - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id002
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id003 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: "2.6"
43
+ type: :development
44
+ version_requirements: *id003
45
+ description: Easily require date arguments for command line apps. Includes some formats by default but can have custom regexp set. Pass a block to override raising an argument error if the fetch fails.
46
+ email:
47
+ - keith@railscoder.net
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files: []
53
+
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - lib/require_date.rb
60
+ - require_date.gemspec
61
+ - spec/require_date_spec.rb
62
+ homepage: https://github.com/kthibodeaux/require_date
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - *id004
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - *id004
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 2.0.14
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Easily require date arguments
85
+ test_files:
86
+ - spec/require_date_spec.rb