Class: Vivlio::Starter::CLI::Metrics::ConfigLoader
- Inherits:
-
Object
- Object
- Vivlio::Starter::CLI::Metrics::ConfigLoader
- Defined in:
- lib/vivlio/starter/cli/metrics/config_loader.rb
Overview
metrics 設定を読み込み解決する
Constant Summary collapse
- DEFAULT_PRESETS =
デフォルトのプリセット設定
{ 'compact' => { 'chapter' => { 'min' => 1000, 'ideal' => [1500, 3000], 'max' => 5000 }, 'section' => { 'min' => 300, 'ideal' => [500, 1000], 'max' => 1500 } }, 'standard' => { 'chapter' => { 'min' => 3000, 'ideal' => [5000, 10_000], 'max' => 15_000 }, 'section' => { 'min' => 800, 'ideal' => [1500, 3000], 'max' => 4000 } }, 'commercial' => { 'chapter' => { 'min' => 5000, 'ideal' => [8000, 12_000], 'max' => 20_000 }, 'section' => { 'min' => 1500, 'ideal' => [2000, 4000], 'max' => 6000 } } }.freeze
- DEFAULT_VOCABULARY =
{ 'kanji_ratio' => { 'min' => 20, 'ideal' => [25, 35], 'max' => 45 }, 'word_length' => { 'min' => 1.5, 'ideal' => [2.0, 2.5], 'max' => 3.0 }, 'ttr' => { 'min' => 0.3, 'ideal' => [0.5, 0.7], 'max' => 1.0 } }.freeze
- DEFAULT_STRUCTURE =
{ 'sentence_length' => { 'min' => 20, 'ideal' => [40, 60], 'max' => 80 }, 'clause_length' => { 'min' => 15, 'ideal' => [30, 40], 'max' => 50 } }.freeze
- DEFAULT_READABILITY =
{ 'easy' => 30, 'standard' => 60 }.freeze
- DEFAULT_LABELS =
{ 'too_short' => '加筆検討', 'too_long' => 'やや長い', 'monotonous' => '表現が単調', 'too_complex' => 'やや難解' }.freeze
Instance Method Summary collapse
-
#exclude_chapters ⇒ Object
除外する章番号のリストを取得する.
-
#initialize(book_config = nil) ⇒ ConfigLoader
constructor
A new instance of ConfigLoader.
-
#labels ⇒ Object
警告ラベルを取得する.
-
#readability_thresholds ⇒ Object
読解難度のしきい値を取得する.
-
#structure_thresholds ⇒ Object
文構造のしきい値を取得する.
-
#vocabulary_thresholds ⇒ Object
語彙難度のしきい値を取得する.
-
#volume_thresholds ⇒ Object
選択されたプリセットの章・節しきい値を取得する.
Constructor Details
#initialize(book_config = nil) ⇒ ConfigLoader
Returns a new instance of ConfigLoader.
57 58 59 60 |
# File 'lib/vivlio/starter/cli/metrics/config_loader.rb', line 57 def initialize(book_config = nil) @book_config = book_config || load_book_config @metrics_config = @book_config['metrics'] || {} end |
Instance Method Details
#exclude_chapters ⇒ Object
除外する章番号のリストを取得する
70 71 72 73 |
# File 'lib/vivlio/starter/cli/metrics/config_loader.rb', line 70 def exclude_chapters raw = metrics_config['exclude_chapters'] || %w[00 90-98 99] (raw) end |
#labels ⇒ Object
警告ラベルを取得する
95 96 97 98 |
# File 'lib/vivlio/starter/cli/metrics/config_loader.rb', line 95 def labels config_labels = metrics_config['labels'] || {} DEFAULT_LABELS.merge(config_labels).transform_keys(&:to_sym) end |
#readability_thresholds ⇒ Object
読解難度のしきい値を取得する
86 87 88 89 90 91 92 |
# File 'lib/vivlio/starter/cli/metrics/config_loader.rb', line 86 def readability_thresholds config_readability = metrics_config['readability'] || {} { easy: config_readability['easy'] || DEFAULT_READABILITY['easy'], standard: config_readability['standard'] || DEFAULT_READABILITY['standard'] } end |
#structure_thresholds ⇒ Object
文構造のしきい値を取得する
81 82 83 |
# File 'lib/vivlio/starter/cli/metrics/config_loader.rb', line 81 def structure_thresholds merge_with_defaults(metrics_config, DEFAULT_STRUCTURE, %w[sentence_length clause_length]) end |
#vocabulary_thresholds ⇒ Object
語彙難度のしきい値を取得する
76 77 78 |
# File 'lib/vivlio/starter/cli/metrics/config_loader.rb', line 76 def vocabulary_thresholds merge_with_defaults(metrics_config, DEFAULT_VOCABULARY, %w[kanji_ratio word_length ttr]) end |
#volume_thresholds ⇒ Object
選択されたプリセットの章・節しきい値を取得する
63 64 65 66 67 |
# File 'lib/vivlio/starter/cli/metrics/config_loader.rb', line 63 def volume_thresholds preset_name = metrics_config['use'] || 'standard' preset = resolve_preset(preset_name) symbolize_thresholds(preset) end |