class Gruff::Layer

Attributes

name[R]

Public Class Methods

new(base_dir, folder_name) click to toggle source
# 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

Public Instance Methods

observe(obj) click to toggle source

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
path() click to toggle source

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
update(value) click to toggle source

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