Skip to content

Commit

Permalink
TimetableSlot now uses standard data mappings.
Browse files Browse the repository at this point in the history
  • Loading branch information
tszolar committed Jul 16, 2014
1 parent c9fb30d commit cffbf5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
19 changes: 7 additions & 12 deletions lib/kosapi_client/entity/timetable_slot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ module KOSapiClient
module Entity
class TimetableSlot

attr_reader :id, :day, :parity, :room

def initialize(id, day, parity, room)
@id = id
@day = day
@parity = parity
@room = room
end

def self.parse(contents)
new(contents[:id], contents[:day], contents[:parity], contents[:room])
end
include DataMappings

map_data :id, Integer
map_data :day, Integer
map_data :duration, Integer
map_data :first_hour, Integer
map_data :parity, Enum
map_data :room, Link

end
end
Expand Down
11 changes: 7 additions & 4 deletions spec/kosapi_client/entity/timetable_slot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
describe '.parse' do

it 'can be parsed from a hash' do
slot = TimetableSlot.parse({id: 42, day: :monday, parity: :odd, room: 'A:1324'})
slot = TimetableSlot.parse({id: '42', day: '1', first_hour: '3', duration: '2', parity: 'BOTH', room: { __contents__: 'no-title', xlink_href: 'rooms/10010205/' }})
expect(slot.id).to eq 42
expect(slot.day).to eq :monday
expect(slot.parity).to eq :odd
expect(slot.room).to eq 'A:1324'
expect(slot.day).to eq 1
expect(slot.first_hour).to eq 3
expect(slot.duration).to eq 2
expect(slot.parity).to eq :both
expect(slot.room).to be_an_instance_of(Link)
expect(slot.room.href).to eq 'rooms/10010205/'
end

end
Expand Down

0 comments on commit cffbf5d

Please sign in to comment.