Class: Presentation
- Inherits:
-
Object
- Object
- Presentation
- Defined in:
- lib/testing.rb
Constant Summary collapse
- @@slide_counter =
0
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
Class Method Summary collapse
- .define_slide(include: 0, variant: nil, class_name: nil, &contents) ⇒ Object
- .define_slide_sequence(class_name, method, test_class_name, test_method, test_sequence, variant = nil) ⇒ Object
Instance Method Summary collapse
- #center(slide) ⇒ Object
- #display_slide ⇒ Object
-
#initialize(first_slide = 1) ⇒ Presentation
constructor
A new instance of Presentation.
- #method_source(class_name, method, hide = //) ⇒ Object
- #play ⇒ Object
- #print_help ⇒ Object
-
#record ⇒ Object
requires MacOS + ImageMagick.
- #run_tests(sequence) ⇒ Object
- #size ⇒ Object
- #slides ⇒ Object
- #split_screen ⇒ Object
Constructor Details
#initialize(first_slide = 1) ⇒ Presentation
Returns a new instance of Presentation.
214 215 216 |
# File 'lib/testing.rb', line 214 def initialize( = 1) self.current = @current = end |
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
212 213 214 |
# File 'lib/testing.rb', line 212 def current @current end |
Class Method Details
.define_slide(include: 0, variant: nil, class_name: nil, &contents) ⇒ Object
352 353 354 355 356 357 358 359 360 361 |
# File 'lib/testing.rb', line 352 def self.(include: 0, variant: nil, class_name: nil, &contents) @@slide_counter += 1 = proc { |number| self.send("slide_#{number}".to_sym) } define_method "slide_#{@@slide_counter}".to_sym do instance_eval("#{class_name}.send(:#{variant.to_s})") if variant current_number = __method__.to_s.split('_').last.to_i (include != 0 ? instance_exec(current_number + include, &) : []) + instance_exec(&contents) end end |
.define_slide_sequence(class_name, method, test_class_name, test_method, test_sequence, variant = nil) ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/testing.rb', line 339 def self.(class_name, method, test_class_name, test_method, test_sequence, variant = nil) if class_name (variant: variant, class_name: class_name) do method_source(class_name,method,/_slow|_fast|_wrong|_correct/) end { run_tests(test_sequence.split('_')[0..-2].join('_')) } end if test_class_name (include: class_name ? -2 : 0){method_source(test_class_name,test_method) } { run_tests(test_sequence) } end end |
Instance Method Details
#center(slide) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/testing.rb', line 291 def center() lines = .size blank = Term.height - lines half, rest = blank.divmod(2) puts "\n" * half .each do |l| content, format = l.split('#') content ||= l format = (format || '').split('.') display = format.include?('CODE') ? content.ljust(Term.width - 10) : content.center(Term.width) result = (format - ['CODE']).inject(display) do |res, f| res.send(f.to_sym) end puts result end puts "\n" * (half + rest - 1) rescue ArgumentError => e "Παρακαλώ μεγαλώστε το παράθυρο για εμφανιστεί η σελίδα..." puts "Error: #{e.}" puts e.backtrace puts ["lines:", lines, "height:", Term.height, "width:", Term.width, "blank:", blank, "half:", half, "rest:", rest].join(" ") @current -= 1 ensure pager = "Slide: %d / %d >" % [current, size] prompt = "b: back one,<number>: goto slide, <enter>: next, h,?: help, q: quit" printf prompt + pager.rjust(Term.width - prompt.size - 3) end |
#display_slide ⇒ Object
283 284 285 |
# File 'lib/testing.rb', line 283 def center(self.send(@slides[@current - 1])) end |
#method_source(class_name, method, hide = //) ⇒ Object
330 331 332 333 334 335 336 337 338 |
# File 'lib/testing.rb', line 330 def method_source(class_name,method,hide = //) ["class #{class_name.to_s}", ""] + class_name. instance_method(method). source. gsub(hide,''). split("\n"). map { |c| c + '#CODE' } end |
#play ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/testing.rb', line 228 def play while current <= size key = STDIN.gets.chomp case key when 'b' self.current -= 1 when /[0-9][0-9]*/ self.current = key.to_i when 'q' exit when 'h', '?' print_help else self.current += 1 end system('clear') end end |
#print_help ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/testing.rb', line 258 def print_help system('clear') puts "Press... to:" puts "h,? print this help" puts "q quit" puts "<number> go to slide <number>" puts "<enter> go to next slide" puts "b go to previous slide" puts "Run... to:" puts "ruby #{$0} RECORD, to generate pdf of presentation" STDIN.gets.chomp end |
#record ⇒ Object
requires MacOS + ImageMagick
248 249 250 251 252 253 254 255 256 |
# File 'lib/testing.rb', line 248 def record # requires MacOS + ImageMagick (1..size).each do |index| self.current = index sleep 1 `screencapture slide_#{"%04d" % (index)}.png` end `convert slide_*.png presentation.pdf` end |
#run_tests(sequence) ⇒ Object
323 324 325 326 327 328 |
# File 'lib/testing.rb', line 323 def run_tests(sequence) ['Run Tests'] + if ARGV[0] !~ /RUN_TESTS/ `ruby testing.rb #{['RUN_TESTS', sequence].join('_')}` end.split("\n").map { |c| c + '#CODE' } end |
#size ⇒ Object
279 280 281 |
# File 'lib/testing.rb', line 279 def size .size end |
#slides ⇒ Object
271 272 273 274 275 276 277 |
# File 'lib/testing.rb', line 271 def @slides ||= self.class.public_instance_methods(true). grep(/\Aslide_/). map(&:to_s). sort_by { |s| s.split('_').last.to_i }. map(&:to_sym) end |
#split_screen ⇒ Object
287 288 289 |
# File 'lib/testing.rb', line 287 def split_screen ["", "", "", "#underline", "", "", ""] end |