Class: Gruff::Layer
- Inherits:
-
Object
- Object
- Gruff::Layer
- Defined in:
- lib/gruff/scene.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(base_dir, folder_name) ⇒ Layer
constructor
A new instance of Layer.
-
#observe(obj) ⇒ Object
Register this layer so it receives updates from the group.
-
#path ⇒ Object
Returns the full path to the selected image, or a blank string.
-
#update(value) ⇒ Object
Choose the appropriate filename for this layer, based on the input.
Constructor Details
#initialize(base_dir, folder_name) ⇒ Layer
Returns a new instance of Layer.
121 122 123 124 125 126 |
# File 'lib/gruff/scene.rb', line 121 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$/ }.sort @selected_filename = select_default end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
119 120 121 |
# File 'lib/gruff/scene.rb', line 119 def name @name end |
Instance Method Details
#observe(obj) ⇒ Object
Register this layer so it receives updates from the group
129 130 131 |
# File 'lib/gruff/scene.rb', line 129 def observe(obj) obj.add_observer self end |
#path ⇒ Object
Returns the full path to the selected image, or a blank string
152 153 154 155 156 157 158 |
# File 'lib/gruff/scene.rb', line 152 def path unless @selected_filename.nil? || @selected_filename.empty? return File.join(@base_dir, @name, @selected_filename) end '' end |
#update(value) ⇒ Object
Choose the appropriate filename for this layer, based on the input
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/gruff/scene.rb', line 134 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 "#{Regexp.last_match(1)}#{Regexp.last_match(2)}" else select_default end # Finally, try to use 'default' if we're still blank @selected_filename ||= select_default end |