Class: OnlyofficeTestrailWrapper::TestrailApiObject

Inherits:
Object
  • Object
show all
Defined in:
lib/onlyoffice_testrail_wrapper/testrail_api_object.rb

Overview

Base class for all Testrail API objects

Instance Method Summary collapse

Instance Method Details

#init_from_hash(hash) ⇒ Object

Fill object data from hash with data

Parameters:

  • hash (Hash)

    with data

Returns:



9
10
11
12
# File 'lib/onlyoffice_testrail_wrapper/testrail_api_object.rb', line 9

def init_from_hash(hash)
  hash.each { |key, value| instance_variable_set(:"@#{key}", value) }
  self
end

#name_id_pairs(array, name_key = 'name') ⇒ Hash

Generate hash wih pars of name:id

Parameters:

  • array (Array<Hash>)

    of raw data

  • name_key (String, Symbol) (defaults to: 'name')

    how name key is called in hash

Returns:

  • (Hash)

    result hash data



18
19
20
21
22
23
24
# File 'lib/onlyoffice_testrail_wrapper/testrail_api_object.rb', line 18

def name_id_pairs(array, name_key = 'name')
  raise 'First argument must be Array!' unless array.is_a?(Array)

  result_hash = {}
  array.reverse_each { |element| result_hash[element[name_key]] = element['id'] }
  result_hash
end