Class: Fitting::Cover::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
12
13
14
# File 'lib/fitting/cover/response.rb', line 7

def initialize(response)
  @cover_json_schemas = Fitting::Cover::JSONSchema.new(response.json_schema)
  @json_schemas = @cover_json_schemas.json_schemas + [response.json_schema]
  @combinations = @cover_json_schemas.combinations
  @flags = @cover_json_schemas.json_schemas.map do |json_schema|
    JSON::Validator.validate(json_schema, response.body)
  end
end

Instance Attribute Details

#combinationsObject (readonly)

Returns the value of attribute combinations.



18
19
20
# File 'lib/fitting/cover/response.rb', line 18

def combinations
  @combinations
end

#flagsObject (readonly)

Returns the value of attribute flags.



20
21
22
# File 'lib/fitting/cover/response.rb', line 20

def flags
  @flags
end

#json_schemasObject (readonly)

Returns the value of attribute json_schemas.



16
17
18
# File 'lib/fitting/cover/response.rb', line 16

def json_schemas
  @json_schemas
end

Instance Method Details

#to_hashObject



32
33
34
35
36
37
38
# File 'lib/fitting/cover/response.rb', line 32

def to_hash
  {
    'json_schemas' => json_schemas,
    'combinations' => combinations,
    'flags' => flags
  }
end

#update(response) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/fitting/cover/response.rb', line 22

def update(response)
  index = 0
  @cover_json_schemas.json_schemas.map do |json_schema|
    flag = JSON::Validator.validate(json_schema, response.body)
    @flags[index] = @flags[index] || flag
    index += 1
  end
  self
end