Class: UBXDSupportRota::SupportRota
- Inherits:
-
Object
- Object
- UBXDSupportRota::SupportRota
- Defined in:
- lib/ubxd_support_rota/support_rota.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build_from_data(data) ⇒ Object
- #footer ⇒ Object
- #header_for_date(date) ⇒ Object
- #to_s(format = nil) ⇒ Object
-
#to_wiki_format ⇒ Object
January 2011== {| border=“1” ! Week Commencing !! Monday !! Tuesday !! Wednesday !! Thursday !! Friday !! Saturday !! Sunday !! Comment |- ! 3 Jan 11 | Austin || Murray || Murray || Murray || Murray || Murray || Murray || |- ! 10 Jan 11 | Murray || Nigel || Nigel ||Nigel || Nigel || Nigel || Nigel || (replaced Alex ‘cos he’s on baby-leave) |- ! 17 Jan 11 | Nigel || Alan || Alan || Alan || Alan || Alan || Alan || |- ! 24 Jan 11 | Alan || Jolyon || Jolyon || Jolyon || Jolyon || Jolyon || Jolyon || |- ! 31 Jan 11 | Jolyon || Simon || Simon || Simon || Simon || Simon || Simon || |- |}.
Class Method Details
.create_from_yaml_file(filename) ⇒ Object
5 6 7 |
# File 'lib/ubxd_support_rota/support_rota.rb', line 5 def self.create_from_yaml_file(filename) new.build_from_data(YAML.load(File.read(filename))) end |
Instance Method Details
#build_from_data(data) ⇒ Object
9 10 11 12 13 |
# File 'lib/ubxd_support_rota/support_rota.rb', line 9 def build_from_data(data) @start_date = Date.parse(data["start_date"].to_s) @support_sequence = data["support_sequence"].map { |s| Shift.new(s) } self end |
#footer ⇒ Object
81 82 83 |
# File 'lib/ubxd_support_rota/support_rota.rb', line 81 def "|}\n" end |
#header_for_date(date) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/ubxd_support_rota/support_rota.rb', line 72 def header_for_date(date) <<EOT % [date.strftime("%B %Y")] ==%s== {| border="1" ! Week Commencing !! Monday !! Tuesday !! Wednesday !! Thursday !! Friday !! Saturday !! Sunday !! Comment |- EOT end |
#to_s(format = nil) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/ubxd_support_rota/support_rota.rb', line 15 def to_s(format = nil) if format.to_s == "wiki" to_wiki_format else inspect end end |
#to_wiki_format ⇒ Object
January 2011==
{| border=“1” ! Week Commencing !! Monday !! Tuesday !! Wednesday !! Thursday !! Friday !! Saturday !! Sunday !! Comment |- ! 3 Jan 11 | Austin || Murray || Murray || Murray || Murray || Murray || Murray || |- ! 10 Jan 11 | Murray || Nigel || Nigel ||Nigel || Nigel || Nigel || Nigel || (replaced Alex ‘cos he’s on baby-leave) |- ! 17 Jan 11 | Nigel || Alan || Alan || Alan || Alan || Alan || Alan || |- ! 24 Jan 11 | Alan || Jolyon || Jolyon || Jolyon || Jolyon || Jolyon || Jolyon || |- ! 31 Jan 11 | Jolyon || Simon || Simon || Simon || Simon || Simon || Simon || |- |}
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ubxd_support_rota/support_rota.rb', line 44 def to_wiki_format if @start_date.wday != 1 raise "The start date should be a Monday" end s = header_for_date(@start_date) current_date = @start_date previous_shift = @support_sequence.shift @support_sequence.each_with_index do |shift, index| s += shift.to_wiki_format(previous_shift, current_date) previous_shift = shift current_date += 7 if current_date.mday < 8 s += unless index == @support_sequence.size - 1 # not the last shift in sequence s += header_for_date(current_date) end end end if current_date.mday >= 8 s += end s end |