Parent

Gruff::Layer

Attributes

name[R]

Public Class Methods

new(base_dir, folder_name) click to toggle source
     # File lib/gruff/scene.rb, line 133
133:   def initialize(base_dir, folder_name)
134:     @base_dir = base_dir.to_s
135:     @name = folder_name.to_s
136:     @filenames = Dir.open(File.join(base_dir, folder_name)).entries.select { |file| file =~ /^[^.]+\.png$/ }
137:     @selected_filename = select_default
138:   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
141:   def observe(obj)
142:     obj.add_observer self
143:   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
164:   def path
165:     unless @selected_filename.nil? || @selected_filename.empty?
166:       return File.join(@base_dir, @name, @selected_filename)
167:     end
168:     ''
169:   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
146:   def update(value)
147:     @selected_filename =  case value.to_s
148:                           when /^(true|false)$/
149:                             select_boolean value
150:                           when /^(\w|\s)+$/
151:                             select_string value
152:                           when /^-?(\d+\.)?\d+$/
153:                             select_numeric value
154:                           when /(\d\d):(\d\d):\d\d/
155:                             select_time "#{$1}#{$2}"
156:                           else
157:                             select_default
158:                           end
159:     # Finally, try to use 'default' if we're still blank
160:     @selected_filename ||= select_default
161:   end

Private Instance Methods

file_exists_or_blank(filename) click to toggle source

Returns the string “#{filename}.png”, if it exists.

Failing that, it returns default.png, or ’’ if that doesn’t exist.

     # File lib/gruff/scene.rb, line 205
205:   def file_exists_or_blank(filename)
206:     @filenames.include?("#{filename}.png") ? "#{filename}.png" : select_default
207:   end
select_boolean(value) click to toggle source

Match “true.png“ or “false.png“

     # File lib/gruff/scene.rb, line 174
174:   def select_boolean(value)
175:     file_exists_or_blank value.to_s
176:   end
select_default() click to toggle source
     # File lib/gruff/scene.rb, line 198
198:   def select_default
199:     @filenames.include?("default.png") ? "default.png" : ''
200:   end
select_numeric(value) click to toggle source

Match -5 to _5.png

     # File lib/gruff/scene.rb, line 179
179:   def select_numeric(value)
180:     file_exists_or_blank value.to_s.gsub('-', '_')
181:   end
select_string(value) click to toggle source

Match “partly cloudy” to “partly_cloudy.png“

     # File lib/gruff/scene.rb, line 194
194:   def select_string(value)
195:     file_exists_or_blank value.to_s.gsub(' ', '_')
196:   end
select_time(value) click to toggle source
     # File lib/gruff/scene.rb, line 183
183:   def select_time(value)
184:     times = @filenames.map { |filename| filename.gsub('.png', '') }
185:     times.each_with_index do |time, index|
186:       if (time > value) && (index > 0)
187:         return "#{times[index - 1]}.png"
188:       end
189:     end
190:     return "#{times.last}.png"
191:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.