Class: VivlioStarter::CLI::IndexCommands::TermLine
- Inherits:
-
Data
- Object
- Data
- VivlioStarter::CLI::IndexCommands::TermLine
- Defined in:
- lib/vivlio_starter/cli/index/term_line.rb
Overview
レビューファイルの用語行
Constant Summary collapse
- LINE =
用語行の綴り。
[フラグ]『NEW! ラベル』**用語** (読み)と行末。 ここを変えると 9 つの読み取りすべてに効く——だからこそ 1 箇所に置く。 /^- \[([^\]]*)\](?: `(NEW!|Today)`)? \*\*(.+?)\*\* \(([^)]+)\)(.*)$/- FLAG_AND_MAIN =
フラグ本体と主要参照を分ける。
igm?21,22→ ['ig', ['21','22'], true] /\A([^m]*)m(\?)?(.*)\z/- INDEX_FLAGS =
%w[i ig gi x].freeze
- GLOSSARY_FLAGS =
%w[g ig gi].freeze
- REJECT_BOTH_FLAGS =
%w[r -ig -gi].freeze
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#suggested ⇒ Object
readonly
Returns the value of attribute suggested.
-
#term ⇒ Object
readonly
Returns the value of attribute term.
-
#trailer ⇒ Object
readonly
Returns the value of attribute trailer.
-
#yomi ⇒ Object
readonly
Returns the value of attribute yomi.
Class Method Summary collapse
-
.build(flags, main: [], suggested: false) ⇒ Object
フラグ欄を組み立てる。主要参照は章番号だけのときフラグへ収める ——
[igm21#Markdown とは]は読みにくいので、そういう値は子行に譲る。. -
.in_flag?(tokens) ⇒ Boolean
フラグ欄へ収めてよい値か(章番号だけか).
-
.parse(line) ⇒ Object
1 行を解釈する。用語行でなければ nil.
-
.scan(content) ⇒ Object
文字列に含まれる用語行をすべて拾う.
Instance Method Summary collapse
- #glossary? ⇒ Boolean
- #index? ⇒ Boolean
-
#pending? ⇒ Boolean
保留(
[ ]や空欄). - #reject_both? ⇒ Boolean
- #reject_glossary? ⇒ Boolean
- #reject_index? ⇒ Boolean
-
#score ⇒ Object
行末から拾えるスコア.
-
#unrejecting? ⇒ Boolean
除外済みリストから拾い上げる対象(セクション 4 で復帰マークが付いた行).
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags
38 39 40 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 38 def flags @flags end |
#label ⇒ Object (readonly)
Returns the value of attribute label
38 39 40 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 38 def label @label end |
#main ⇒ Object (readonly)
Returns the value of attribute main
38 39 40 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 38 def main @main end |
#suggested ⇒ Object (readonly)
Returns the value of attribute suggested
38 39 40 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 38 def suggested @suggested end |
#term ⇒ Object (readonly)
Returns the value of attribute term
38 39 40 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 38 def term @term end |
#trailer ⇒ Object (readonly)
Returns the value of attribute trailer
38 39 40 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 38 def trailer @trailer end |
#yomi ⇒ Object (readonly)
Returns the value of attribute yomi
38 39 40 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 38 def yomi @yomi end |
Class Method Details
.build(flags, main: [], suggested: false) ⇒ Object
フラグ欄を組み立てる。主要参照は章番号だけのときフラグへ収める
——[igm21#Markdown とは] は読みにくいので、そういう値は子行に譲る。
66 67 68 69 70 71 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 66 def build(flags, main: [], suggested: false) tokens = Array(main) return "[#{flags}]" unless in_flag?(tokens) "[#{flags}m#{suggested ? '?' : ''}#{tokens.join(',')}]" end |
.in_flag?(tokens) ⇒ Boolean
フラグ欄へ収めてよい値か(章番号だけか)
74 75 76 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 74 def in_flag?(tokens) tokens.any? && tokens.all? { it.to_s.match?(/\A\d+\z/) } end |
.parse(line) ⇒ Object
1 行を解釈する。用語行でなければ nil
52 53 54 55 56 57 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 52 def parse(line) m = LINE.match(line) or return nil flags, main, suggested = split_flags(m[1]) new(flags:, main:, suggested:, term: m[3], yomi: m[4], label: m[2], trailer: m[5].to_s) end |
.scan(content) ⇒ Object
文字列に含まれる用語行をすべて拾う
60 61 62 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 60 def scan(content) content.to_s.lines.filter_map { parse(it) } end |
Instance Method Details
#glossary? ⇒ Boolean
89 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 89 def glossary? = GLOSSARY_FLAGS.include?(flags) |
#index? ⇒ Boolean
88 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 88 def index? = INDEX_FLAGS.include?(flags) |
#pending? ⇒ Boolean
保留([ ] や空欄)
98 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 98 def pending? = flags.strip.empty? |
#reject_both? ⇒ Boolean
90 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 90 def reject_both? = REJECT_BOTH_FLAGS.include?(flags) |
#reject_glossary? ⇒ Boolean
92 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 92 def reject_glossary? = flags == '-g' |
#reject_index? ⇒ Boolean
91 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 91 def reject_index? = flags == '-i' |
#score ⇒ Object
行末から拾えるスコア
101 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 101 def score = trailer[/- スコア:\s*([\d.]+)/, 1]&.to_f |
#unrejecting? ⇒ Boolean
除外済みリストから拾い上げる対象(セクション 4 で復帰マークが付いた行)
95 |
# File 'lib/vivlio_starter/cli/index/term_line.rb', line 95 def unrejecting? = (INDEX_FLAGS + GLOSSARY_FLAGS).include?(flags) |