Class Gruff::Layer
In: lib/gruff/scene.rb
Parent: Object

Methods

new   observe   path   update  

Attributes

name  [R] 

Public Class methods

[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 =~ /^[^.]+\.png$/ }
    @selected_filename = select_default
  end

Public Instance methods

Register this layer so it receives updates from the group

[Source]

# 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

[Source]

# 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

[Source]

# File lib/gruff/scene.rb, line 146
  def update(value)
    @selected_filename =  case value.to_s
                          when /^(true|false)$/
                            select_boolean value
                          when /^(\w|\s)+$/
                            select_string value
                          when /^-?(\d+\.)?\d+$/
                            select_numeric value
                          when /(\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

[Validate]