Class: Velocify::ResponseReader
- Inherits:
-
Object
- Object
- Velocify::ResponseReader
- Defined in:
- lib/velocify/response_reader.rb
Class Method Summary collapse
-
.read(kind:, response:) ⇒ Object
Convenience method to create a ResponseReader.
Instance Method Summary collapse
-
#all_titles ⇒ String
A list of all the titles.
- #find_by_title(title) ⇒ Object
-
#find_id_by_title(title) ⇒ String
Retrieve the id of a ‘kind` given a title.
- #find_value_by_title(title) ⇒ Object
- #search_by_title(title) ⇒ Object
Class Method Details
.read(kind:, response:) ⇒ Object
Convenience method to create a ResponseReader
Velocify model objects
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_titles ⇒ String
Returns 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
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 |