3months_staff_schedule 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ *.rbc
2
+ .bundle
3
+ .config
4
+ .yardoc
5
+ Gemfile.lock
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ rdoc
12
+ spec/reports
13
+ test/tmp
14
+ test/version_tmp
15
+ tmp
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'staff_schedule/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "3months_staff_schedule"
8
+ gem.version = StaffSchedule::VERSION
9
+ gem.authors = ["Josh McArthur"]
10
+ gem.email = ["joshua.mcarthur@gmail.com"]
11
+ gem.description = %q{Generate a report from the 3months staff schedule}
12
+ gem.summary = %q{Generate a report from the 3months staff schedule}
13
+ gem.homepage = ""
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_dependency "google_drive"
21
+ gem.add_dependency "highline"
22
+ gem.add_dependency "activesupport"
23
+ gem.add_development_dependency "rake"
24
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in 3months_staff_schedule.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Josh McArthur
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # 3monthsStaffSchedule
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem '3months_staff_schedule'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install 3months_staff_schedule
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "google_drive"
4
+ require "highline/import"
5
+ require "active_support/all"
6
+
7
+
8
+ def determine_name_from_email!
9
+ return unless @@config[:email]
10
+ @@config[:name] = @@config[:email].split("@")[0].humanize
11
+ end
12
+
13
+ def session
14
+ @@session ||= GoogleDrive.login(@@config[:email], @@config[:password])
15
+ end
16
+
17
+ def schedule
18
+ @@schedule ||= session.spreadsheet_by_key(@@config[:spreadsheet]).worksheets[0]
19
+ end
20
+
21
+
22
+ def store_config!
23
+ File.open(@@config[:config_file], 'wb+') { |f| f.write([@@config[:email], @@config[:password], @@config[:name]].join(',')) }
24
+ end
25
+
26
+ def load_config!
27
+ if File.exists?(@@config[:config_file])
28
+ say "Loading config from #{@@config[:config_file]}"
29
+ @@config[:email], @@config[:password], @@config[:name] = File.read(@@config[:config_file]).split(',')
30
+ end
31
+ end
32
+
33
+ def get_entries!
34
+ puts "\n\n"
35
+ schedule.rows.each_with_index do |row, index|
36
+ next if index < @@config[:skip_rows]
37
+ if is_us?(row) and has_hours?(row)
38
+ header = project_header_for_row(row, index)
39
+ print_formatted_row(row, header)
40
+ end
41
+ end
42
+ end
43
+
44
+ def is_us?(row)
45
+ return row.to_s.include?(@@config[:name])
46
+ end
47
+
48
+ def has_hours?(row)
49
+ return row[5].present?
50
+ end
51
+
52
+ def print_formatted_row(row, header)
53
+ formatted_row = row[4].tap do |desc|
54
+ desc << " (#{row[5]} hours)"
55
+ desc.insert(0, "<%= color('#{header}\n', :cyan) %>")
56
+ end
57
+ say formatted_row
58
+ puts "\n"
59
+ end
60
+
61
+ # Step up through the worksheet until we find a row that meets our requirements
62
+ def project_header_for_row(row, index)
63
+ return nil if row.nil?
64
+
65
+ # Does the row meet our requirements:
66
+ # - one column present only
67
+ # - only first column filled in
68
+ row_size = row.dup.delete_if(&:empty?).length
69
+ return row[0] if row_size == 1 and !row[0].blank?
70
+
71
+ # Otherwise recurse
72
+ return project_header_for_row(schedule.rows[index - 1], index - 1)
73
+ end
74
+
75
+
76
+
77
+ @@config = {
78
+ spreadsheet: "0AlNg4D7kwNRpcG5vSU0wNmY2TkRoU29UcEktZUkxV3c",
79
+ skip_rows: 10,
80
+ config_file: File.expand_path("~/.staff_schedule")
81
+ }
82
+
83
+ say("<%= color('What am I doing this week?!', :green) %>")
84
+ load_config!
85
+
86
+ if @@config[:email].nil?
87
+ @@config[:email] = ask("Imma gonna need your email username:\t")
88
+ determine_name_from_email!
89
+
90
+ unless agree("Is your name in the schedule #{@@config[:name]}?\t")
91
+ @@config[:name] = ask("Imma gonna need your name in the staff schedule as well then:\t")
92
+ end
93
+ end
94
+
95
+ if @@config[:password].nil?
96
+ @@config[:password] = ask("Imma gonna need you to generate a one time password (2-factor auth), or enter your account password:\t") { |q| q.echo = "*" }
97
+ end
98
+
99
+
100
+
101
+ store_config!
102
+ get_entries!
103
+
104
+
105
+
106
+
107
+
108
+
109
+
@@ -0,0 +1,5 @@
1
+ require "staff_schedule/version"
2
+
3
+ module StaffSchedule
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module StaffSchedule
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: 3months_staff_schedule
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josh McArthur
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: google_drive
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: highline
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
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: '0'
78
+ description: Generate a report from the 3months staff schedule
79
+ email:
80
+ - joshua.mcarthur@gmail.com
81
+ executables:
82
+ - staff_schedule
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - 3months_staff_schedule.gemspec
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - bin/staff_schedule
93
+ - lib/3months_staff_schedule.rb
94
+ - lib/staff_schedule/version.rb
95
+ - pkg/3months_staff_schedule-0.0.1.gem
96
+ - pkg/3months_staff_schedule-0.0.2.gem
97
+ homepage: ''
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ segments:
110
+ - 0
111
+ hash: 662801639659897258
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: 662801639659897258
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.24
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Generate a report from the 3months staff schedule
127
+ test_files: []