Skip to content

Instantly share code, notes, and snippets.

@davelyon
Created September 19, 2010 05:12
Show Gist options
  • Save davelyon/586414 to your computer and use it in GitHub Desktop.
Save davelyon/586414 to your computer and use it in GitHub Desktop.
require 'image'
require 'movie'
require 'event_registry'
class HelioEvent
EVENT_STARTTIME_KEY = "event_starttime"
EVENT_ENDTIME_KEY = "event_endtime"
EVENT_ARCHIVEDATE_KEY = "kb_archivdate"
EVENT_UID_KEY = "kb_archivid"
EVENT_BBOX_KEY = "hpc_bbox"
class << self # Class Methods
attr_accessor :images, :movies
def has_movie(klass)
@movies ||= []
@movies << klass
end
def has_image(klass)
@images ||= []
@images << klass
end
def inherited(klass)
EventRegistry.register_class(klass)
end
def short_name
@shortname
end
def shortname(name)
@shortname = name
end
end
attr_accessor :start_date, :end_date, :archive_date, :duration_seconds, :event_coords, :event_boundingbox, :uid
def initialize(data)
if(data[EVENT_BBOX_KEY].nil?); raise "Missing hpc_coords";end
@uid = data[EVENT_UID_KEY].gsub(/ivo:\/\/helio-informatics\.org\//, "")
@start_date = Time.parse(data[EVENT_STARTTIME_KEY])
@end_date = Time.parse(data[EVENT_ENDTIME_KEY])
#@archive_date = Time.parse(data[EVENT_ARCHIVEDATE_KEY])
@duration_seconds = (@end_date - @start_date).to_i
@event_boundingbox = data[EVENT_BBOX_KEY]
@movies = self.class.movies
@images = self.class.images
end
def warm_cache?
not @images.nil?
end
def make_movie?
not @movies.nil?
end
def urls(type)
urls = []
type.each do |url|
url.types.each do |urltype|
urls << { :url => url.url_from_event(self,urltype), :type => urltype }
end
end
urls
end
def image_urls
urls(@images)
end
def movie_urls
urls(@movies)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment