Class: Hachiwari::CLI
- Inherits:
-
Thor
- Object
- Thor
- Hachiwari::CLI
- Defined in:
- lib/hachiwari/cli.rb
Defined Under Namespace
Classes: Results
Constant Summary collapse
- @@db =
YAML::Store.new("#{Dir.home}/.hachiwari")
- @@results =
@@db.transaction { @@db[:results] }
Class Method Summary collapse
Instance Method Summary collapse
- #i(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language) ⇒ Object
- #info(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language) ⇒ Object
- #s(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language) ⇒ Object
- #status(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language, save = true) ⇒ Object
- #version ⇒ Object
Class Method Details
.save ⇒ Object
14 15 16 |
# File 'lib/hachiwari/cli.rb', line 14 def save @@db.transaction { @@db[:results] = @@results } end |
Instance Method Details
#i(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language) ⇒ Object
56 57 58 |
# File 'lib/hachiwari/cli.rb', line 56 def i(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language) status(wins, losses, target, language, false) end |
#info(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language) ⇒ Object
51 52 53 |
# File 'lib/hachiwari/cli.rb', line 51 def info(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language) status(wins, losses, target, language, false) end |
#s(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language) ⇒ Object
46 47 48 |
# File 'lib/hachiwari/cli.rb', line 46 def s(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language) status(wins, losses, target, language) end |
#status(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language, save = true) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hachiwari/cli.rb', line 21 def status(wins = @@results.wins, losses = @@results.losses, target = @@results.target, language = @@results.language, save = true) wins = wins.to_i if ARGV[1] losses = losses.to_i if ARGV[2] target = target.to_i if ARGV[3] language = language.to_sym if ARGV[4] if save @@results.wins = wins @@results.losses = losses @@results.target = target @@results.language = language CLI.save end case language when :ja puts "#{wins+losses} 戦 #{wins} 勝 #{losses} 敗 勝率 #{winning_percentage(wins, losses)} % です" puts "あと #{reach_wins(wins, losses)} 勝で 勝率 #{(@@results.target).to_i} % です" when :en puts "#{wins+losses} games #{wins} wins #{losses} losses a winning percentage of #{winning_percentage(wins, losses)} %." puts "You need #{reach_wins(wins, losses)} more wins to reach #{(@@results.target).to_i} %" end end |