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.



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

def initialize(options = {})
  @components = options.fetch(:components) { [] }
  @score = options.fetch(:score) { 0.0 }
  @unrecognized = options.fetch(:unrecognized) { [] }
  @valid = options.fetch(:valid) { false }
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



5
6
7
# File 'lib/inci_score/response.rb', line 5

def components
  @components
end

#scoreObject (readonly)

Returns the value of attribute score.



5
6
7
# File 'lib/inci_score/response.rb', line 5

def score
  @score
end

#unrecognizedObject (readonly)

Returns the value of attribute unrecognized.



5
6
7
# File 'lib/inci_score/response.rb', line 5

def unrecognized
  @unrecognized
end

#validObject (readonly)

Returns the value of attribute valid.



5
6
7
# File 'lib/inci_score/response.rb', line 5

def valid
  @valid
end

Instance Method Details

#to_jsonObject



14
15
16
# File 'lib/inci_score/response.rb', line 14

def to_json
  { components: @components, unrecognized: @unrecognized, score: @score, valid: @valid }.to_json
end

#to_sObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/inci_score/response.rb', line 18

def to_s
  %Q{
TOTAL SCORE:
  \t#{@score}
VALID STATE:
  \t#{@valid}
COMPONENTS:
  #{@components.map { |c| "\t#{c}" }.join("\n")}
UNRECOGNIZED:
  #{@unrecognized.map { |c| "\t#{c}" }.join("\n")}
  }
end