lib/osm/evening.rb in osm-0.1.16 vs lib/osm/evening.rb in osm-0.1.17

- old
+ new

@@ -1,5 +1,7 @@ +# TODO with next version bump - rename to Meeting, also rename meeting_date to date + module Osm class Evening < Osm::Model class Activity; end # Ensure the constant exists for the validators @@ -62,11 +64,11 @@ # @param [Osm::Section, Fixnum] section the section (or its ID) to get the programme for # @param [Osm::term, Fixnum, nil] term the term (or its ID) to get the programme for, passing nil causes the current term to be used # @!macro options_get # @return [Array<Osm::Evening>] # TODO Change to get_all in next version bump - def self.get_programme(api, section, term, options={}) + def self.get_programme(api, section, term=nil, options={}) section_id = section.to_i term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, section).id : term.to_i cache_key = ['programme', section_id, term_id] if !options[:no_cache] && cache_exist?(api, cache_key) && get_user_permission(api, section_id, :programme).include?(:read) @@ -228,9 +230,31 @@ data = api.perform_query("users.php?action=getActivityRequirements&date=#{meeting_date.strftime(Osm::OSM_DATE_FORMAT)}&sectionid=#{section.id}&section=#{section.type}") cache_write(api, cache_key, data) return data + end + + + def <=>(another) + begin + compare = self.section_id <=> another.section_id + return compare unless compare == 0 + + compare = self.meeting_date <=> another.meeting_date + return compare unless compare == 0 + + my_start_time = self.start_time.split(':').map{ |i| i.to_i } + another_start_time = another.start_time.split(':').map{ |i| i.to_i } + compare = my_start_time[0] <=> another_start_time[0] + return compare unless compare == 0 + compare = my_start_time[1] <=> another_start_time[1] + return compare unless compare == 0 + + return self.id <=> another.id + rescue NoMethodError + return 0 + end end private class Activity