ubxd_support_rota 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.
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $:.unshift(lib_dir) unless
5
+ $:.include?(lib_dir) || $:.include?(File.expand_path(lib_dir))
6
+
7
+ require 'ubxd_support_rota'
8
+
9
+ yaml_file = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "support_rota.yml"))
10
+ support_rota = UBXDSupportRota::SupportRota.create_from_yaml_file(yaml_file)
11
+ puts support_rota.to_s(:wiki)
@@ -0,0 +1,25 @@
1
+ require 'yaml'
2
+
3
+ module UBXDSupportRota
4
+ class Shift
5
+ attr_reader :name, :comment
6
+
7
+ def initialize(attributes = {})
8
+ @name = attributes["name"]
9
+ @comment = attributes["comment"]
10
+ end
11
+
12
+ def to_s
13
+ "<name: \"#{@name}\" comment: \"#{@comment}\">"
14
+ end
15
+
16
+ def to_wiki_format(previous_shift, date)
17
+ values = [date.strftime("%e %b %Y"), previous_shift.name] + [name] * 6 + [comment||""]
18
+ <<EOT % values
19
+ ! %s
20
+ | %s || %s || %s || %s || %s || %s || %s || %s
21
+ |-
22
+ EOT
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,85 @@
1
+ require 'yaml'
2
+
3
+ module UBXDSupportRota
4
+ class SupportRota
5
+ def self.create_from_yaml_file(filename)
6
+ new.build_from_data(YAML.load(File.read(filename)))
7
+ end
8
+
9
+ def build_from_data(data)
10
+ @start_date = Date.parse(data["start_date"].to_s)
11
+ @support_sequence = data["support_sequence"].map { |s| Shift.new(s) }
12
+ self
13
+ end
14
+
15
+ def to_s(format = nil)
16
+ if format.to_s == "wiki"
17
+ to_wiki_format
18
+ else
19
+ inspect
20
+ end
21
+ end
22
+
23
+ # ==January 2011==
24
+ # {| border="1"
25
+ # ! Week Commencing !! Monday !! Tuesday !! Wednesday !! Thursday !! Friday !! Saturday !! Sunday !! Comment
26
+ # |-
27
+ # ! 3 Jan 11
28
+ # | Austin || Murray || Murray || Murray || Murray || Murray || Murray ||
29
+ # |-
30
+ # ! 10 Jan 11
31
+ # | Murray || Nigel || Nigel ||Nigel || Nigel || Nigel || Nigel || (replaced Alex 'cos he's on baby-leave)
32
+ # |-
33
+ # ! 17 Jan 11
34
+ # | Nigel || Alan || Alan || Alan || Alan || Alan || Alan ||
35
+ # |-
36
+ # ! 24 Jan 11
37
+ # | Alan || Jolyon || Jolyon || Jolyon || Jolyon || Jolyon || Jolyon ||
38
+ # |-
39
+ # ! 31 Jan 11
40
+ # | Jolyon || Simon || Simon || Simon || Simon || Simon || Simon ||
41
+ # |-
42
+ # |}
43
+
44
+ def to_wiki_format
45
+ if @start_date.wday != 1
46
+ raise "The start date should be a Monday"
47
+ end
48
+
49
+ s = header_for_date(@start_date)
50
+ current_date = @start_date
51
+ previous_shift = @support_sequence.shift
52
+
53
+ @support_sequence.each_with_index do |shift, index|
54
+ s += shift.to_wiki_format(previous_shift, current_date)
55
+ previous_shift = shift
56
+ current_date += 7
57
+ if current_date.mday < 8
58
+ s += footer
59
+ unless index == @support_sequence.size - 1 # not the last shift in sequence
60
+ s += header_for_date(current_date)
61
+ end
62
+ end
63
+ end
64
+
65
+ if current_date.mday >= 8
66
+ s += footer
67
+ end
68
+
69
+ s
70
+ end
71
+
72
+ def header_for_date(date)
73
+ <<EOT % [date.strftime("%B %Y")]
74
+ ==%s==
75
+ {| border="1"
76
+ ! Week Commencing !! Monday !! Tuesday !! Wednesday !! Thursday !! Friday !! Saturday !! Sunday !! Comment
77
+ |-
78
+ EOT
79
+ end
80
+
81
+ def footer
82
+ "|}\n"
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,4 @@
1
+ module UBXDSupportRota
2
+ # We're doing this because bundler did it this way
3
+ VERSION = "0.0.1" unless defined?(::UBXDSupportRota::VERSION)
4
+ end
@@ -0,0 +1,6 @@
1
+ require "ubxd_support_rota/support_rota"
2
+ require "ubxd_support_rota/shift"
3
+
4
+ if Gem.available?("ruby-debug")
5
+ require "ruby-debug"
6
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ubxd_support_rota
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Tom ten Thij
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-17 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: An easy way to generate the support rota for Unboxed Consulting in wiki markup
23
+ email:
24
+ - ruby@tomtenthij.nl
25
+ executables:
26
+ - ubxd_support_rota
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - bin/ubxd_support_rota
33
+ - lib/ubxd_support_rota/shift.rb
34
+ - lib/ubxd_support_rota/support_rota.rb
35
+ - lib/ubxd_support_rota/version.rb
36
+ - lib/ubxd_support_rota.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/unboxed/ubxd_support_rota
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: An easy way to generate the support rota for Unboxed Consulting in wiki markup
71
+ test_files: []
72
+