Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__),'../..','ext_pr1/lib')
- require 'ext_pr1_v4'
- # Teilufgabe 1
- # Transformation der Wochentage in OO
- # Konstanten für Werte
- DAY_SYM_SEQ = [:Mo, :Di, :Mi, :Do, :Fr, :Sa, :So]
- DAY_NUM_SEQ = [1, 2, 3, 4, 5, 6, 7]
- # Konstanten für Indices
- DAYS_IN_WEEK = DAY_SYM_SEQ.size
- DAY_INDEX_SEQ = (0...DAYS_IN_WEEK)
- # Klasse für Tag
- # Day ::= DaySym | DayNum
- def_class(:Day,[:day]) {
- def invariant?
- day.sym? or day.num?
- end
- def to_day_num
- idx + 1
- end
- def to_day_sym
- DAY_SYM_SEQ[to_idx]
- end
- def to_idx
- DAY_SYM_SEQ.index(sym)
- end
- }
- # Klasse für die Wochentage aus DAY_SYM_SEQ
- # DaySym ::= DaySym[:sym] :: {:Mo, :Di, :Mi, :Do, :Fr, :Sa, :So}
- # Tests {DaySym[:Mo] => DayNum[1], DaySym[:Mo] => DaySym[:Mo], DaySym[:Mo] =>
- # }
- def_class(:DaySym,[:sym]) {
- def invariant?
- sym.in?(DAY_SYM_SEQ) and DAY_SYM_SEQ.include?(sym)
- end
- def to_day_num
- idx + 1
- end
- def to_day_sym
- DAY_SYM_SEQ[to_idx]
- end
- def to_idx
- DAY_SYM_SEQ.index(sym)
- end
- }
- # Klasse für die Wochentage aus DAY_NUM_SEQ
- # DayNum ::= DayNum[:num] :: {1,2,3,4,5,6,7}
- # Tests {DayNum[1] => DayNum[1], DayNum[7] => DayNum[7],
- # DayNum[0] => Err, DayNum[8] => Err}
- def_class(:DayNum, [:num]) {
- def invariant?
- num.int? and DAY_NUM_SEQ.include?(num)
- end
- def to_day_num
- idx + 1
- end
- def to_day_sym
- DAY_SYM_SEQ[idx]
- end
- def to_idx
- DAY_NUM_SEQ.index(num)
- end
- }
- # Klasse für Index von Tag
- # DayIdx ::= DayIdx[:idx] :: {(0...DAYS_IN_WEEK)}
- def_class(:DayIdx,[:idx]) {
- def invariant?
- idx.int? and DAY_NUM_SEQ.index.include?(idx)
- end
- def to_day_num
- idx + 1
- end
- def to_day_sym
- DAY_SYM_SEQ[idx]
- end
- }
- # Hilfsmethoden:
- # Ermittelt den Index des angegebenen num im Array DAY_NUM_SEQ (Hilfsmethode)
- #def to_idx
- # DAY_NUM_SEQ.index(num)
- #end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement