Class: Vivlio::Starter::CLI::StatBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio/starter/cli/metrics.rb

Overview

個別 Markdown の統計情報を構築する

Instance Method Summary collapse

Instance Method Details

#build(path) ⇒ Object

単一ファイルから統計情報ハッシュを生成する



155
156
157
158
159
160
161
162
163
# File 'lib/vivlio/starter/cli/metrics.rb', line 155

def build(path)
  absolute = Pathname.new(path)
  absolute = Pathname.new('.') / path unless absolute.absolute?
  content = File.read(absolute, encoding: 'UTF-8')
  base_metrics(content).merge(sentence_metrics(content)).merge(clause_metrics(content)).merge('path' => path)
rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError => e
  Common.log_warn("エンコーディングエラーのためスキップします: #{path} (#{e.message})")
  blank_stat(path)
end