biweek_finder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ README.rdoc
3
+ ChangeLog.rdoc
4
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ Gemfile.lock
2
+ coverage
3
+ html/
4
+ pkg/
5
+ vendor/cache/*.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/ChangeLog.rdoc ADDED
@@ -0,0 +1,4 @@
1
+ === 0.1.0 / 2013-04-04
2
+
3
+ * Initial release:
4
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Michael Westbom
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,42 @@
1
+ = biweek_finder
2
+
3
+ * {Homepage}[https://rubygems.org/gems/biweek_finder]
4
+ * {Documentation}[http://rubydoc.info/gems/biweek_finder/frames]
5
+ * {Email}[mailto:totallymike at gmail.com]
6
+
7
+ == Description
8
+
9
+ Pass the gem a directory containing subdirectories named after biweeks, and return a list of those directories.
10
+
11
+ It's not terribly complex.
12
+
13
+ == Features
14
+
15
+ Reads directories, ignores files.
16
+
17
+ == Examples
18
+
19
+ require 'biweek_finder'
20
+
21
+ # Assume /path/to/dir contains these guys:
22
+ # 20120102/
23
+ # 20120304/
24
+ # another_dir/
25
+ # 20120506 # < not a directory
26
+
27
+ BiweekFinder.from_path '/path/to/dir'
28
+ #=> ['20120102', '20120304']
29
+
30
+ == Requirements
31
+
32
+ Just rspec and simplecov for development purposes.
33
+
34
+ == Install
35
+
36
+ $ gem install biweek_finder
37
+
38
+ == Copyright
39
+
40
+ Copyright (c) 2013 Michael Westbom
41
+
42
+ See LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'bundler'
7
+ rescue LoadError => e
8
+ warn e.message
9
+ warn "Run `gem install bundler` to install Bundler."
10
+ exit -1
11
+ end
12
+
13
+ begin
14
+ Bundler.setup(:development)
15
+ rescue Bundler::BundlerError => e
16
+ warn e.message
17
+ warn "Run `bundle install` to install missing gems."
18
+ exit e.status_code
19
+ end
20
+
21
+ require 'rake'
22
+
23
+ require 'rubygems/tasks'
24
+ Gem::Tasks.new
25
+
26
+ require 'rdoc/task'
27
+ RDoc::Task.new do |rdoc|
28
+ rdoc.title = "biweek_finder"
29
+ end
30
+ task :doc => :rdoc
31
+
32
+ require 'rspec/core/rake_task'
33
+ RSpec::Core::RakeTask.new
34
+
35
+ task :test => :spec
36
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/biweek_finder/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "biweek_finder"
7
+ gem.version = BiweekFinder::VERSION
8
+ gem.summary = "Finds properly formatted biweek folders."
9
+ gem.description = "Used for an internal project but possibly useful elsewhere?"
10
+ gem.license = "MIT"
11
+ gem.authors = ["Michael Westbom"]
12
+ gem.email = "totallymike@gmail.com"
13
+ gem.homepage = "https://rubygems.org/gems/biweek_finder"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_development_dependency 'bundler', '~> 1.0'
21
+ gem.add_development_dependency 'rake', '~> 0.8'
22
+ gem.add_development_dependency 'rdoc', '~> 3.0'
23
+ gem.add_development_dependency 'rspec', '~> 2.4'
24
+ gem.add_development_dependency 'simplecov', '~> 0.7'
25
+ gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
26
+ end
@@ -0,0 +1,29 @@
1
+ require 'biweek_finder/version'
2
+
3
+ module BiweekFinder
4
+ def self.from_path(path = '.')
5
+ sort from_a subdirectories(path)
6
+ end
7
+
8
+ def self.subdirectories(path = '.')
9
+ dir = Dir.open(path)
10
+ dir.select {|f| File.directory?(File.join(path, f))}
11
+ end
12
+
13
+ def self.from_a(arr = [])
14
+ arr.find_all do |name|
15
+ self.is_biweek? name
16
+ end
17
+ end
18
+
19
+ def self.sort(arr = [])
20
+ arr.sort {|a, b| a <=> b}
21
+ end
22
+
23
+ def self.is_biweek?(str)
24
+ if /^20/ =~ str
25
+ true
26
+ else false
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ module BiweekFinder
2
+ # biweek_finder version
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'biweek_finder'
3
+
4
+ describe BiweekFinder do
5
+ describe "pattern matching" do
6
+ it "can recognize a biweek timestamp" do
7
+ expect(BiweekFinder.is_biweek? '20122930').to be true
8
+ expect(BiweekFinder.is_biweek? 'fooDir').to be false
9
+ end
10
+ end
11
+
12
+ describe "sorting" do
13
+ it "sorts the biweeks appropriately" do
14
+ expect(BiweekFinder.sort %w{20121112 20120102}).to eq %w{20120102 20121112}
15
+ end
16
+ end
17
+
18
+ describe "Directory reading" do
19
+ dirs = %w{20130910 20131112 20081112 fooDir}
20
+ files = %w{20131111.txt file1.txt file2.txt}
21
+
22
+ before(:all) do
23
+ $temp_dir = Dir.mktmpdir
24
+ dirs.each do |dir|
25
+ Dir.mkdir File.join($temp_dir, dir)
26
+ end
27
+ files.each do |file|
28
+ File.new(File.join($temp_dir, file), 'w')
29
+ end
30
+ end
31
+
32
+ after(:all) do
33
+ dirs.each do |dir|
34
+ Dir.rmdir File.join($temp_dir, dir)
35
+ end
36
+ files.each do |file|
37
+ File.unlink File.join($temp_dir, file)
38
+ end
39
+ Dir.rmdir $temp_dir
40
+ end
41
+
42
+ it "should return only directories named after biweeks" do
43
+ expect(BiweekFinder.from_path $temp_dir).
44
+ to eq %w{20081112 20130910 20131112}
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'simplecov'
3
+ require 'tmpdir'
4
+
5
+ SimpleCov.start
6
+
7
+ require './lib/biweek_finder'
8
+
9
+ include BiweekFinder
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: biweek_finder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Westbom
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.8'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.8'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.4'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.4'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0.7'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '0.7'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rubygems-tasks
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '0.2'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '0.2'
110
+ description: Used for an internal project but possibly useful elsewhere?
111
+ email: totallymike@gmail.com
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files: []
115
+ files:
116
+ - .document
117
+ - .gitignore
118
+ - .rspec
119
+ - ChangeLog.rdoc
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.rdoc
123
+ - Rakefile
124
+ - biweek_finder.gemspec
125
+ - lib/biweek_finder.rb
126
+ - lib/biweek_finder/version.rb
127
+ - spec/biweek_finder_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: https://rubygems.org/gems/biweek_finder
130
+ licenses:
131
+ - MIT
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ segments:
143
+ - 0
144
+ hash: 225285235
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ segments:
152
+ - 0
153
+ hash: 225285235
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 1.8.25
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: Finds properly formatted biweek folders.
160
+ test_files:
161
+ - spec/biweek_finder_spec.rb
162
+ - spec/spec_helper.rb