Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

choiceの複数選択と連続要素略記 #490

Merged
merged 4 commits into from
Jul 30, 2021
Merged

choiceの複数選択と連続要素略記 #490

merged 4 commits into from
Jul 30, 2021

Conversation

ysakasin
Copy link
Member

重複なし複数選択

choise2[A,B,C] のようにすることで要素の中から指定した数だけ重複なしで複数個選ぶ。

  • choice2[A,B,C]
    • "A", "B", "C" から重複なしで2個選ぶ
  • choice3[A,B,C]
    • "A", "B", "C" から全てが選ばれるが、選ばれる順番によって表示順が変わる。実質的に ["A", "B", "C"].shuffle
  • choice4[A,B,C]
    • 選択数が要素数を超えているのでエラー

連続要素の省略表記

指定したい要素が「AからD」のように連続する項目の場合に「A-D」と省略して記述できる。
パースする際にchoice[A-D]ならchoice[A,B,C,D]だと解釈され実行される。

利用できる省略表記

  • アルファベット大文字1字の範囲: A-G
  • アルファベット小文字1字の範囲: a-z
  • 数値の範囲: 10-30

省略表記が展開される条件

以下の両方を満たすときに略記が展開される。

  • 省略表記1つのみが指定され、他の要素がないとき
    • choice[A-D, Z]choice[A-D, X-Z] では展開しない
  • [first]-[last]first <= last であるとき

デザインチョイスなど

choice2 vs 2choice

2choiceだとchoiceを2回っぽいので。あと、choice2の方が英語の語順に近い。

省略表記は1つしか書けなくて他と共存できない件

choiceは対象の要素をかなり自由に書けてしまうので、思ったように書けないというのを避けるために限定的な状況でのみ発動するようにする。

アルファベット1文字制限

Rubyで複数文字のRangeString#uptoto_aすると挙動が怪しい……

irb(main):001:0> ('a'..'bb').to_a
=> ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "aa", "ab", "ac", "ad", "ae", "af", "ag", "ah", "ai", "aj", "ak", "al", "am", "an", "ao", "ap", "aq", "ar", "as", "at", "au", "av", "aw", "ax", "ay", "az", "ba", "bb"]
irb(main):002:0> ('b'..'bb').to_a
=> ["b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "aa", "ab", "ac", "ad", "ae", "af", "ag", "ah", "ai", "aj", "ak", "al", "am", "an", "ao", "ap", "aq", "ar", "as", "at", "au", "av", "aw", "ax", "ay", "az", "ba", "bb"]
irb(main):003:0> ('c'..'bb').to_a
=> []

ちなみに仕様とのこと
https://bugs.ruby-lang.org/issues/13663#note-4

Ref.

@ysakasin ysakasin added the 新機能 新機能の実装やリクエスト label Jul 28, 2021
@codecov
Copy link

codecov bot commented Jul 28, 2021

Codecov Report

Merging #490 (bc244b0) into master (d330926) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #490   +/-   ##
=======================================
  Coverage   95.39%   95.40%           
=======================================
  Files         296      296           
  Lines       18900    18932   +32     
=======================================
+ Hits        18030    18062   +32     
  Misses        870      870           
Impacted Files Coverage Δ
lib/bcdice/common_command/choice.rb 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d330926...bc244b0. Read the comment docs.

@GenKuzumochi
Copy link
Contributor

お疲れさまです。

choice2 10 20 30のような空白区切りは採用しない予定でしょうか?数値を追加するだけで2個3個選択にできるほうがわかりやすいのと、空白区切り便利なのでぜひ対応があると嬉しいです。

@ysakasin
Copy link
Member Author

@GenKuzumochi テストや説明に便宜上書いてないだけで、このPRですでに choice2 10 20 30 は実行可能になっています。

@ysakasin ysakasin merged commit 6d56417 into master Jul 30, 2021
@ysakasin ysakasin deleted the multi_choice branch July 30, 2021 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
新機能 新機能の実装やリクエスト
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants