Class: JLPT::AnalysisResult
- Inherits:
-
Object
- Object
- JLPT::AnalysisResult
- 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
-
#kanji_breakdown ⇒ Object
readonly
Returns the value of attribute kanji_breakdown.
-
#kanji_density ⇒ Object
readonly
Returns the value of attribute kanji_density.
-
#recommended_level ⇒ Object
readonly
Returns the value of attribute recommended_level.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#sentence_count ⇒ Object
readonly
Returns the value of attribute sentence_count.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#vocab_distribution ⇒ Object
readonly
Returns the value of attribute vocab_distribution.
-
#word_count ⇒ Object
readonly
Returns the value of attribute word_count.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(attrs = {}) ⇒ AnalysisResult
constructor
A new instance of AnalysisResult.
- #inspect ⇒ Object
- #to_h ⇒ Object
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_breakdown ⇒ Object (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_density ⇒ Object (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 |
#recommended_level ⇒ Object (readonly)
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 |
#score ⇒ Object (readonly)
Returns the value of attribute score.
9 10 11 |
# File 'lib/jlpt/core/analysis_result.rb', line 9 def score @score end |
#sentence_count ⇒ Object (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 |
#text ⇒ Object (readonly)
Returns the value of attribute text.
9 10 11 |
# File 'lib/jlpt/core/analysis_result.rb', line 9 def text @text end |
#vocab_distribution ⇒ Object (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_count ⇒ Object (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 |
#inspect ⇒ Object
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_h ⇒ Object
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 |