language_cards 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68244f488493379dce92d1879109a72e4031bc1a7ccfb0e26a29bc99ba65201e
4
- data.tar.gz: 5d2ad35183a3e9cb97d18092d2abf47623b45fdeca0febba8bab22264b141778
3
+ metadata.gz: f386cb5a496e136e07ed8dfb2aeddcdc3cdc556eef68068345e6beb11b6b4884
4
+ data.tar.gz: 1c226ee6bc088df7e6317767862bf183fbd05773458e0948162e4cac44adf578
5
5
  SHA512:
6
- metadata.gz: 53e788b04c2d03bec478647f0fb1dadba2c698c977d1e152b88e27e51f25f507232697a7f3db8476ca6beef97ccca6394b70cbc6480c1f6dba87c82be837312b
7
- data.tar.gz: 843d4a4b94f07afd463eff60b5ed61452f6e5bd4e12b424d1496aec7b5dc2ddfb6173a9de16eab46432d6feb1a51d1ac837535f4042d4f3d5537376a1141f452
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
@@ -1,3 +1,3 @@
1
1
  module LanguageCards
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/locales/en.yml CHANGED
@@ -15,6 +15,9 @@ en:
15
15
  ScoreMenu:
16
16
  Score: Your score is
17
17
  OutOf: out of
18
+ Timer:
19
+ Timer: Timer
20
+ AverageSeconds: second average
18
21
  Errors:
19
22
  UpperCollection: Upper level collection container.\nYou need to use a deeper collection for cards.
20
23
  InvalidMapping: >
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.0
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-01 00:00:00.000000000 Z
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