# File lib/gruff/scene.rb, line 133 def initialize(base_dir, folder_name) @base_dir = base_dir.to_s @name = folder_name.to_s @filenames = Dir.open(File.join(base_dir, folder_name)).entries.select { |file| file =~ %r^[^.]+\.png$/ } @selected_filename = select_default end
Register this layer so it receives updates from the group
# File lib/gruff/scene.rb, line 141 def observe(obj) obj.add_observer self end
Returns the full path to the selected image, or a blank string
# File lib/gruff/scene.rb, line 164 def path unless @selected_filename.nil? || @selected_filename.empty? return File.join(@base_dir, @name, @selected_filename) end '' end
Choose the appropriate filename for this layer, based on the input
# File lib/gruff/scene.rb, line 146 def update(value) @selected_filename = case value.to_s when %r^(true|false)$/ select_boolean value when %r^(\w|\s)+$/ select_string value when %r^-?(\d+\.)?\d+$/ select_numeric value when %r(\d\d):(\d\d):\d\d/ select_time "#{$1}#{$2}" else select_default end # Finally, try to use 'default' if we're still blank @selected_filename ||= select_default end