Class: InciScore::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/inci_score/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @components = options.fetch(:components) { [] }
  @score = options.fetch(:score) { 0.0 }
  @unrecognized = options.fetch(:unrecognized) { [] }
  @precision = options.fetch(:precision) { 0 }
  freeze
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



7
8
9
# File 'lib/inci_score/response.rb', line 7

def components
  @components
end

#precisionObject (readonly)

Returns the value of attribute precision.



7
8
9
# File 'lib/inci_score/response.rb', line 7

def precision
  @precision
end

#scoreObject (readonly)

Returns the value of attribute score.



7
8
9
# File 'lib/inci_score/response.rb', line 7

def score
  @score
end

#unrecognizedObject (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_jsonObject



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_sObject



22
23
24
# File 'lib/inci_score/response.rb', line 22

def to_s
  [score_str, precision_str, components_str, unrecognized_str].join
end