language_cards 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/language_cards/timer.rb +45 -0
- data/lib/language_cards/user_interface.rb +8 -2
- data/lib/language_cards/version.rb +1 -1
- data/locales/en.yml +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f386cb5a496e136e07ed8dfb2aeddcdc3cdc556eef68068345e6beb11b6b4884
|
4
|
+
data.tar.gz: 1c226ee6bc088df7e6317767862bf183fbd05773458e0948162e4cac44adf578
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9ce5e60f9d421518e939cf8d0a93f679f09649f80302bb003136088116344aa0febffb01627bf1050e208709ab3c7c6d6bf331d9f65c6cd3deb44664a694100
|
7
|
+
data.tar.gz: 6ed54b21a65cd3c50cc328dc02624efcdd6019e2b235f83707fee4409de898c653ace8e306e0ef673d13f722ac5fea3bfd4f46e466aef0e58b5055ce20e56d6f
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
module LanguageCards
|
3
|
+
class Timer
|
4
|
+
def initialize
|
5
|
+
@stamps = []
|
6
|
+
@mark = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def mark
|
10
|
+
if @mark
|
11
|
+
@stamps << -(@mark - (@mark = Time.now))
|
12
|
+
else
|
13
|
+
@mark = Time.now
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def time?
|
18
|
+
!times.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def h # human
|
22
|
+
"%02d:%02d:%02d" % [total/3600%24, total/60%60, total%60]
|
23
|
+
end
|
24
|
+
|
25
|
+
def average
|
26
|
+
total.fdiv(times.size)
|
27
|
+
end
|
28
|
+
|
29
|
+
def ha # human average
|
30
|
+
"%0.2f #{I18n.t('Timer.AverageSeconds')}" % average rescue ""
|
31
|
+
end
|
32
|
+
|
33
|
+
def times
|
34
|
+
@stamps
|
35
|
+
end
|
36
|
+
|
37
|
+
def last
|
38
|
+
@stamps.last
|
39
|
+
end
|
40
|
+
|
41
|
+
def total
|
42
|
+
@stamps.inject(:+) || 0
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'timer'
|
2
2
|
|
3
3
|
module LanguageCards
|
4
4
|
class UserInterface
|
@@ -31,10 +31,14 @@ MAINMENU
|
|
31
31
|
|
32
32
|
def score_menu(correct:, incorrect:)
|
33
33
|
score = "#{I18n.t 'Game.ScoreMenu.Score'}: #{correct.to_i} #{I18n.t 'Game.ScoreMenu.OutOf'} #{correct.to_i + incorrect.to_i}"
|
34
|
-
|
34
|
+
timer = @timer.time? ? (I18n.t('Timer.Timer') + ": " + @timer.ha) : ""
|
35
|
+
timer = timer + @timer.h.rjust(SUBMENUWIDTH - timer.length)
|
35
36
|
<<-SCOREMENU
|
36
37
|
#{'~' * SUBMENUWIDTH}
|
38
|
+
#{timer}
|
39
|
+
#{'~' * SUBMENUWIDTH}
|
37
40
|
#{score + I18n.t('Menu.Exit').rjust(SUBMENUWIDTH - score.length)}
|
41
|
+
|
38
42
|
#{@last}
|
39
43
|
#{'~' * SUBMENUWIDTH}
|
40
44
|
SCOREMENU
|
@@ -61,9 +65,11 @@ SCOREMENU
|
|
61
65
|
@last = nil
|
62
66
|
if (0..courses.length-1).include? value
|
63
67
|
collection = cards.select_collection(courses(value))
|
68
|
+
@timer = Timer.new
|
64
69
|
begin
|
65
70
|
loop do
|
66
71
|
clear
|
72
|
+
@timer.mark
|
67
73
|
CLI.say score_menu(correct: @correct, incorrect: @incorrect)
|
68
74
|
game_logic(collection)
|
69
75
|
end
|
data/locales/en.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: language_cards
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/language_cards/comparator.rb
|
109
109
|
- lib/language_cards/language_cards.rb
|
110
110
|
- lib/language_cards/mappings.rb
|
111
|
+
- lib/language_cards/timer.rb
|
111
112
|
- lib/language_cards/user_interface.rb
|
112
113
|
- lib/language_cards/version.rb
|
113
114
|
- locales/en.yml
|