Class: GiphyAPI::Image
- Inherits:
-
Object
- Object
- GiphyAPI::Image
- Includes:
- RawDataAttributes
- Defined in:
- lib/giphy_api/resources/image.rb
Constant Summary collapse
- IMAGE_TYPES =
%w(original fixed_height fixed_height_still fixed_height_downsampled fixed_width fixed_width_still fixed_width_downsampled fixed_height_small fixed_height_small_still fixed_width_small fixed_width_small_still downsized downsized_still downsized_large downsized_medium downsized_small original original_still looping preview preview_gif ).freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Image
constructor
A new instance of Image.
Methods included from RawDataAttributes
Constructor Details
#initialize(attributes = {}) ⇒ Image
Returns a new instance of Image.
34 35 36 |
# File 'lib/giphy_api/resources/image.rb', line 34 def initialize(attributes = {}) assign_raw_data(attributes) end |
Class Method Details
.extract_images(payload) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/giphy_api/resources/image.rb', line 13 def self.extract_images payload image_type_mapping = { "image" => "original" } attr_regexp = "(#{accessible_raw_attributes.join('|')})" type_regexp = "(#{IMAGE_TYPES.join('|')})" image_attribute_regexp = Regexp.new("^#{type_regexp}_#{attr_regexp}$") images = {} payload.each do |key, value| next unless image_attribute_regexp.match(key) image_type = key.sub Regexp.new("_#{attr_regexp}$"), '' image_attribute = key.sub Regexp.new("^#{type_regexp}_"), '' type_mapping_value = image_type_mapping[image_type] || image_type images[type_mapping_value] ||= {} images[type_mapping_value][image_attribute] = value end images end |