Class: Cb::Utils::ResponseArrayExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/cb/utils/response_array_extractor.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_hash, key) ⇒ ResponseArrayExtractor

Returns a new instance of ResponseArrayExtractor.



9
10
11
12
13
# File 'lib/cb/utils/response_array_extractor.rb', line 9

def initialize(response_hash, key)
  @response_hash = response_hash
  @key = key
  @singular_key = key[0..key.length-2]
end

Class Method Details

.extract(response_hash, key) ⇒ Object



5
6
7
# File 'lib/cb/utils/response_array_extractor.rb', line 5

def self.extract(response_hash, key)
  self.new(response_hash, key).extract
end

Instance Method Details

#extractObject



15
16
17
18
19
20
21
# File 'lib/cb/utils/response_array_extractor.rb', line 15

def extract
  if response_has_collection?
    extract_array_from_collection
  else
    []
  end
end