/* Generated by Opal 0.9.0 */ (function(Opal) { Opal.dynamic_require_severity = "error"; var OPAL_CONFIG = { method_missing: false, arity_check: false, freezing: true, tainting: true }; function $rb_plus(lhs, rhs) { return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); } function $rb_divide(lhs, rhs) { return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs / rhs : lhs['$/'](rhs); } function $rb_times(lhs, rhs) { return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs * rhs : lhs['$*'](rhs); } function $rb_minus(lhs, rhs) { return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); } function $rb_lt(lhs, rhs) { return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); } function $rb_le(lhs, rhs) { return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs <= rhs : lhs['$<='](rhs); } var self = Opal.top, $scope = Opal, nil = Opal.nil, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass; return (function($base, $super) { function $Game(){}; var self = $Game = $klass($base, $super, 'Game', $Game); var def = self.$$proto, $scope = self.$$scope; def.finished = def.last_errored = def.row_indexes = nil; Opal.defn(self, '$initialize', function() { var self = this; return self.$reset(0); }); Opal.defn(self, '$start', function(milliseconds) { var self = this; return self.$reset(milliseconds); }); Opal.defn(self, '$time_passes', function(milliseconds) { var $a, $b, self = this; if ((($a = self['$finished?']()) !== nil && (!$a.$$is_boolean || $a == true))) { return nil}; return (($a = [milliseconds]), $b = self, $b['$last_milliseconds='].apply($b, $a), $a[$a.length-1]); }); Opal.defn(self, '$finished?', function() { var self = this; return self.finished; }); Opal.defn(self, '$last_errored?', function() { var self = this; return self.last_errored; }); Opal.defn(self, '$key_down', function(key, milliseconds) { var $a, $b, self = this; if ((($a = self['$finished?']()) !== nil && (!$a.$$is_boolean || $a == true))) { return nil}; (($a = [milliseconds]), $b = self, $b['$last_milliseconds='].apply($b, $a), $a[$a.length-1]); self.$keys_pressed()['$<<'](key); if (self.$raw_text()['$[]'](self.$current_index())['$=='](key)) { ($a = self, $a['$current_index=']($rb_plus($a.$current_index(), 1))); ($a = self, $a['$num_correct=']($rb_plus($a.$num_correct(), 1))); (($a = [false]), $b = self, $b['$last_errored='].apply($b, $a), $a[$a.length-1]); } else { ($a = self, $a['$num_incorrect=']($rb_plus($a.$num_incorrect(), 1))); (($a = [true]), $b = self, $b['$last_errored='].apply($b, $a), $a[$a.length-1]); }; if (self.$current_index()['$=='](self.$raw_text().$length())) { return (($a = [true]), $b = self, $b['$finished='].apply($b, $a), $a[$a.length-1]) } else { return nil }; }); Opal.defn(self, '$wpm', function() { var $a, self = this, seconds_in_minute = nil, chars_in_word = nil; if ((($a = self.$seconds_duration()['$zero?']()) !== nil && (!$a.$$is_boolean || $a == true))) { return 0}; seconds_in_minute = 60; chars_in_word = 5; return ($rb_divide($rb_divide($rb_times(self.$num_correct(), seconds_in_minute), self.$seconds_duration()), chars_in_word)).$to_i(); }); Opal.defn(self, '$seconds_duration', function() { var self = this; return $rb_divide(($rb_minus(self.$last_milliseconds(), self.$start_milliseconds())), 1000.0); }); Opal.defn(self, '$formatted_time', function() { var $a, self = this, d = nil, remainder = nil, seconds = nil, minutes = nil, hours = nil, time = nil; d = self.$seconds_duration(); remainder = ($rb_times(d, 10)).$to_i()['$%'](10); d = d.$to_i(); seconds = (d['$%'](60)).$to_s(); while ($rb_lt(seconds.$length(), 2)) { seconds = $rb_plus("0", seconds)}; d = ($rb_divide(d, 60)).$to_i(); minutes = (d['$%'](60)).$to_s(); while ($rb_lt(minutes.$length(), 2)) { minutes = $rb_plus("0", minutes)}; d = ($rb_divide(d, 60)).$to_i(); hours = (d['$%'](60)).$to_s(); while ($rb_lt(hours.$length(), 2)) { hours = $rb_plus("0", hours)}; time = ""; if (hours['$==']("00")) { } else { time = $rb_plus(time, "" + (hours) + ":") }; if (minutes['$==']("00")) { } else { time = $rb_plus(time, "" + (minutes) + ":") }; time = $rb_plus(time, "" + (seconds) + "." + (remainder)); return time; }); Opal.defn(self, '$index_to_row', function(index) { var $a, $b, $c, TMP_1, TMP_2, self = this, indexes = nil, row = nil; ((($a = self.row_indexes) !== false && $a !== nil) ? $a : self.row_indexes = (function() {indexes = []; ($b = ($c = self.$raw_text().$chars().$map()).$with_index, $b.$$p = (TMP_1 = function(char$, i){var self = TMP_1.$$s || this, $a, $b; if (char$ == null) char$ = nil;if (i == null) i = nil; if ((($a = ((($b = char$['$==']("\r")) !== false && $b !== nil) ? $b : char$['$==']("\n"))) !== nil && (!$a.$$is_boolean || $a == true))) { return indexes['$<<'](i) } else { return nil }}, TMP_1.$$s = self, TMP_1), $b).call($c); return indexes;})()); row = 0; ($a = ($b = self.row_indexes).$each, $a.$$p = (TMP_2 = function(crnt_row_index){var self = TMP_2.$$s || this; if (crnt_row_index == null) crnt_row_index = nil; if ($rb_le(index, crnt_row_index)) { return ($breaker.$v = nil, $breaker)}; return row = $rb_plus(row, 1);}, TMP_2.$$s = self, TMP_2), $a).call($b); if ((($a = self['$finished?']()) !== nil && (!$a.$$is_boolean || $a == true))) { row = $rb_plus(row, 1)}; return row; }); Opal.defn(self, '$index_to_col', function(index) { var $a, $b, $c, $d, self = this, i = nil; i = $rb_minus(index, 1); while ((($b = ($c = (($d = $rb_le(0, i)) ? self.$raw_text()['$[]'](i)['$!=']("\r") : $rb_le(0, i)), $c !== false && $c !== nil ?self.$raw_text()['$[]'](i)['$!=']("\n") : $c)) !== nil && (!$b.$$is_boolean || $b == true))) { i = $rb_minus(i, 1)}; return $rb_minus($rb_minus(index, i), 1); }); Opal.defn(self, '$each_char', function(fn) { var $a, $b, TMP_3, self = this, row = nil, i = nil, col = nil; row = 0; i = col = -1; return ($a = ($b = self.$raw_text()).$each_char, $a.$$p = (TMP_3 = function(char$){var self = TMP_3.$$s || this, $a, $b; if (char$ == null) char$ = nil; i = $rb_plus(i, 1); col = $rb_plus(col, 1); fn.$call(char$, i, row, col); if ((($a = ((($b = self.$raw_text()['$[]'](i)['$==']("\r")) !== false && $b !== nil) ? $b : self.$raw_text()['$[]'](i)['$==']("\n"))) !== nil && (!$a.$$is_boolean || $a == true))) { row = $rb_plus(row, 1); return col = -1; } else { return nil };}, TMP_3.$$s = self, TMP_3), $a).call($b); }); self.$private(); self.$attr_accessor("last_milliseconds", "start_milliseconds"); self.$attr_accessor("raw_text", "current_index", "num_correct", "num_incorrect", "keys_pressed", "finished", "last_errored"); return (Opal.defn(self, '$reset', function(milliseconds) { var $a, $b, self = this; (($a = [false]), $b = self, $b['$last_errored='].apply($b, $a), $a[$a.length-1]); (($a = [false]), $b = self, $b['$finished='].apply($b, $a), $a[$a.length-1]); (($a = [milliseconds]), $b = self, $b['$start_milliseconds='].apply($b, $a), $a[$a.length-1]); (($a = [milliseconds]), $b = self, $b['$last_milliseconds='].apply($b, $a), $a[$a.length-1]); (($a = [0]), $b = self, $b['$current_index='].apply($b, $a), $a[$a.length-1]); (($a = [0]), $b = self, $b['$num_correct='].apply($b, $a), $a[$a.length-1]); (($a = [0]), $b = self, $b['$num_incorrect='].apply($b, $a), $a[$a.length-1]); (($a = [[]]), $b = self, $b['$keys_pressed='].apply($b, $a), $a[$a.length-1]); (($a = [" abc\n def\n ghi\n".$gsub(/^ */, "")]), $b = self, $b['$raw_text='].apply($b, $a), $a[$a.length-1]); if ((($a = true) !== nil && (!$a.$$is_boolean || $a == true))) { return (($a = [" So, that's probably everything there is to be found,\n we looked through the code, we looked all around.\n And sure some features are just for the laughs,\n provided on the compiling comedian's behalf.\n\n But you, dear reader, with your attention that spans\n approximately infinite volumes, since this blog first began,\n think what you could achieve if this was what ran\n on production servers in the cloud or on land. [disclaimer]\n\n With your instruction pointer, pointing at places anew.\n And your locations all labeled and ready to ensue.\n No need for a break, a retry, a redo\n Will you be control flowed? No! That won't happen to you!\n Just think of it! Oh! The places you'll goto!\n".$gsub(/^ */, "")]), $b = self, $b['$raw_text='].apply($b, $a), $a[$a.length-1]) } else { return nil }; }), nil) && 'reset'; })($scope.base, null) })(Opal); /* Generated by Opal 0.9.0 */ (function(Opal) { Opal.dynamic_require_severity = "error"; var OPAL_CONFIG = { method_missing: false, arity_check: false, freezing: true, tainting: true }; var self = Opal.top, $scope = Opal, nil = Opal.nil, $breaker = Opal.breaker, $slice = Opal.slice; return $scope.get('Kernel').$exit() })(Opal);