require 'ostruct' module Getapp module Capterra # == Getapp::Capterra::Product Class # # Responsible for transforming Capterra formatted product # into common Getapp product format. # class Product attr_reader :product, :verbose # == Getapp::Capterra::Product::PRODUCT_KEYS_MAPPING Constant # # Hold key mappings for Capterra Product to Getapp Product # PRODUCT_KEYS_MAPPING = { name: :Name, tags: :Categories, twitter: :Twitter }.freeze # == Getapp::Capterra::Product initialize Method # # @param [Hash], Boolean # @return Getapp::Capterra::Product instance. # def initialize(product, verbose = false) @product = product.transform_keys(&:to_sym) @verbose = verbose end # == Getapp::Capterra::Product get Method # # Transform keys from Capterra::Product to Getapp Product # # @param [String] # @return [OpenStruct] # # def get OpenStruct.new(PRODUCT_KEYS_MAPPING.map { |k, v| [v, product[k]] }.to_h) end end end end