Class: InciScore::Response
- Inherits:
-
Object
- Object
- InciScore::Response
- Defined in:
- lib/inci_score/response.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#unrecognized ⇒ Object
readonly
Returns the value of attribute unrecognized.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Response
constructor
A new instance of Response.
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 15 |
# File 'lib/inci_score/response.rb', line 9 def initialize( = {}) @components = .fetch(:components) { [] } @score = .fetch(:score) { 0.0 } @unrecognized = .fetch(:unrecognized) { [] } @precision = .fetch(:precision) { 0 } freeze end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
7 8 9 |
# File 'lib/inci_score/response.rb', line 7 def components @components end |
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
7 8 9 |
# File 'lib/inci_score/response.rb', line 7 def precision @precision end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
7 8 9 |
# File 'lib/inci_score/response.rb', line 7 def score @score end |
#unrecognized ⇒ Object (readonly)
Returns the value of attribute unrecognized.
7 8 9 |
# File 'lib/inci_score/response.rb', line 7 def unrecognized @unrecognized end |
Instance Method Details
#to_json ⇒ Object
17 18 19 20 |
# File 'lib/inci_score/response.rb', line 17 def to_json data = { components: components.map(&:to_h), unrecognized: unrecognized, score: score, precision: precision }.freeze Oj.dump(data, mode: :compat) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/inci_score/response.rb', line 22 def to_s [score_str, precision_str, components_str, unrecognized_str].join end |