Class: Velocify::ResponseReader

Inherits:
Object
  • Object
show all
Defined in:
lib/velocify/response_reader.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.read(kind:, response:) ⇒ Object

Convenience method to create a ResponseReader

Velocify model objects

Parameters:

  • kind (Symbol)

    Choose from [:field]

  • response (Hash)

    The SOAP response received as returned by the other



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/velocify/response_reader.rb', line 12

def read kind:, response:
  singular_key = kind.to_s
  plural_key = singular_key.pluralize
  fields = response
  
  if response.instance_of? Hash
    fields = response[plural_key.to_sym][singular_key.to_sym]
  end
    
  ResponseReader.new kind: kind, elements: fields
end

Instance Method Details

#all_titlesString

Returns a list of all the titles.

Returns:

  • (String)

    a list of all the titles



54
55
56
# File 'lib/velocify/response_reader.rb', line 54

def all_titles
  @elements.map { |el| el["@#{kind}_title".to_sym] }
end

#find_by_title(title) ⇒ Object



48
49
50
51
# File 'lib/velocify/response_reader.rb', line 48

def find_by_title title
  element = select_one_by_title title
  element if element
end

#find_id_by_title(title) ⇒ String

Retrieve the id of a ‘kind` given a title

Parameters:

  • title (String)

    the title of the ‘kind`

Returns:

  • (String)

    the id of the ‘kind` that matches the title you searched for



30
31
32
33
# File 'lib/velocify/response_reader.rb', line 30

def find_id_by_title title
  element = select_one_by_title title
  element["@#{kind}_id".to_sym] if element
end

#find_value_by_title(title) ⇒ Object



35
36
37
38
# File 'lib/velocify/response_reader.rb', line 35

def find_value_by_title title
  element = select_one_by_title title
  element["@value".to_sym] if element
end

#search_by_title(title) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/velocify/response_reader.rb', line 40

def search_by_title title
  element = @elements.select { |el|
    el["@#{kind}_title".to_sym] =~ /#{title}/
  }

  element if element
end