Class: JLPT::AnalysisResult

Inherits:
Object
  • Object
show all
Defined in:
lib/jlpt/core/analysis_result.rb

Overview

Value Object encapsulating JLPT text analysis results.

Supports both method dot-notation and Hash subscripting access.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ AnalysisResult

Returns a new instance of AnalysisResult.



13
14
15
16
17
18
19
20
21
22
# File 'lib/jlpt/core/analysis_result.rb', line 13

def initialize(attrs = {})
  @text               = attrs.fetch(:text, '')
  @recommended_level  = attrs.fetch(:recommended_level, :n5)
  @score              = attrs.fetch(:score, 0.0)
  @kanji_density      = attrs.fetch(:kanji_density, 0.0)
  @vocab_distribution = attrs.fetch(:vocab_distribution, {})
  @kanji_breakdown    = attrs.fetch(:kanji_breakdown, {})
  @sentence_count     = attrs.fetch(:sentence_count, 0)
  @word_count         = attrs.fetch(:word_count, 0)
end

Instance Attribute Details

#kanji_breakdownObject (readonly)

Returns the value of attribute kanji_breakdown.



9
10
11
# File 'lib/jlpt/core/analysis_result.rb', line 9

def kanji_breakdown
  @kanji_breakdown
end

#kanji_densityObject (readonly)

Returns the value of attribute kanji_density.



9
10
11
# File 'lib/jlpt/core/analysis_result.rb', line 9

def kanji_density
  @kanji_density
end

Returns the value of attribute recommended_level.



9
10
11
# File 'lib/jlpt/core/analysis_result.rb', line 9

def recommended_level
  @recommended_level
end

#scoreObject (readonly)

Returns the value of attribute score.



9
10
11
# File 'lib/jlpt/core/analysis_result.rb', line 9

def score
  @score
end

#sentence_countObject (readonly)

Returns the value of attribute sentence_count.



9
10
11
# File 'lib/jlpt/core/analysis_result.rb', line 9

def sentence_count
  @sentence_count
end

#textObject (readonly)

Returns the value of attribute text.



9
10
11
# File 'lib/jlpt/core/analysis_result.rb', line 9

def text
  @text
end

#vocab_distributionObject (readonly)

Returns the value of attribute vocab_distribution.



9
10
11
# File 'lib/jlpt/core/analysis_result.rb', line 9

def vocab_distribution
  @vocab_distribution
end

#word_countObject (readonly)

Returns the value of attribute word_count.



9
10
11
# File 'lib/jlpt/core/analysis_result.rb', line 9

def word_count
  @word_count
end

Instance Method Details

#[](key) ⇒ Object



24
25
26
# File 'lib/jlpt/core/analysis_result.rb', line 24

def [](key)
  public_send(key) if respond_to?(key)
end

#inspectObject



41
42
43
# File 'lib/jlpt/core/analysis_result.rb', line 41

def inspect
  "#<JLPT::AnalysisResult level=#{@recommended_level.to_s.upcase} score=#{@score}>"
end

#to_hObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jlpt/core/analysis_result.rb', line 28

def to_h
  {
    text: @text,
    recommended_level: @recommended_level,
    score: @score,
    kanji_density: @kanji_density,
    vocab_distribution: @vocab_distribution,
    kanji_breakdown: @kanji_breakdown,
    sentence_count: @sentence_count,
    word_count: @word_count
  }
end