Class: RadioVISGenerator::Generator
- Inherits:
-
Object
- Object
- RadioVISGenerator::Generator
- Defined in:
- lib/radiovis-generator.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
-
#run(options) ⇒ Object
Runs the generator! This does all the tying together of things and Stomp interaction.
Constructor Details
#initialize ⇒ Generator
Returns a new instance of Generator.
5 6 7 |
# File 'lib/radiovis-generator.rb', line 5 def initialize Generator.has_dependencies? end |
Class Method Details
.has_dependencies? ⇒ Boolean
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/radiovis-generator.rb', line 87 def self.has_dependencies? unless self.which('inkscape') raise SystemCallError, "Inkscape is required to use this library.\nYou can install it on Ubuntu/Debian with 'sudo apt-get install inkscape'. (And don't worry, it works headlessly and won't install a full GUI stack).\nSpecifically I need 'inkscape' in my PATH." end unless self.which('convert') raise SystemCallError, "ImageMagick is required to use this library.\nYou can install it on Ubuntu/Debian with 'sudo apt-get install imagemagick'.\nSpecifically I need 'convert' in my PATH." end unless self.which('composite') raise SystemCallError, "ImageMagick is required to use this library.\nYou can install it on Ubuntu/Debian with 'sudo apt-get install imagemagick'.\nSpecifically I need 'composite' in my PATH." end end |
Instance Method Details
#run(options) ⇒ Object
Runs the generator! This does all the tying together of things and Stomp interaction. The generator accepts a hash of options:
slides - An array of Slide instances.
url - The root URL at which the pictures can be found from the outside world, ie 'http://blah.com/system/radiovis-images/'.
path - The root path where we should write the images, ie '/opt/www/website/public/system/radiovis-images'
broadcast_parameters - The broadcast parameters for your station in RadioVIS topic format, ie 'fm/ECC/PI/FREQUENCY' for FM (like 'fm/ce1/c08f/10320' for Insanity Radio 103.2 FM)
username - The Stomp username
password - The Stomp password
host - The Stomp host
port - The Stomp port
Sensible defaults are provided for Stomp, but you should set them explicitly.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/radiovis-generator.rb', line 21 def run() defaults = { slides: [], url: 'http://localhost/radiovis/', path: '/tmp/radiovis-output', broadcast_parameters: 'fm/ecc/pi/freq', username: 'system', password: 'manager', host: 'localhost', port: 61613 } = defaults.merge() raise ArgumentsError, "No slide instances provided!" unless [:slides].size > 0 puts "Generator starting - parameters #{.inspect}" begin conn = Stomp::Connection.open [:username], [:password], [:host], [:port], false while true do # Okay - so here's the plan. # We have a bunch of Slide subclasses which contain what we want. # Every so often we check to see if any need rendering and render whichever has the highest priority. = [] [:slides].each do || .push() if .changed? end # If we've got nothing that's changed, pick a redisplay instead. if .size == 0 [:slides].each do || .push() if .redisplay? end end # Pick the lowest priority. .sort_by!{||.priority} = .reverse[0] rescue nil if # Go for it! puts "Rendering #{.inspect}" puts "Chosen from #{.inspect}" = .render([:path]) # Now we go ahead and send those messages. image_topic = "/topic/#{[:broadcast_parameters]}/image" text_topic = "/topic/#{[:broadcast_parameters]}/text" = "SHOW "+[:url]+[:image_small] = "TEXT "+[:text][0..127] puts "Publishing Stomp messages" puts " - #{image_topic} <= #{}" puts " - #{text_topic} <= #{}" conn.publish(image_topic, , {'persistent'=>'false'}) conn.publish(text_topic, , {'persistent'=>'false'}) puts "Done, waiting #{.display_time} seconds to let people read this slide." # Sleep for this long before we display anything else. sleep .display_time else puts "No slide to render, sleeping a second." sleep 1 end end rescue Exception => e puts "Got exception #{e}!" conn.disconnect rescue nil conn = nil sleep 5 retry end end |