<commit_before># module AlexaWebService
  class ShowResponse
    attr_accessor :directives

    def initialize(type:, token:, title:, back_button:, background_image:, image:)
      @directives = [
        {
          "type": "Display.RenderTemplate",
          "template": {
            "type": type,
            "token": token,
            "backButton": back_button,
            "backgroundImage": background_image,
            "title": title,
            "image": image
          }
        }
      ]
    end

    def add_hint(hint_content)
      @directives << {
      "type": "Hint",
      "hint": {
        "type": "PlainText",
        "text": hint_content
        }
      }
    end

    def create_show_image_object(content_description = '', url = '')
      {
        "contentDescription": content_description,
        "sources": [
          {
            "url": url
          }
        ]
      }   
      
    end

    def add_background_image(image_object)
      begin
        @directives.first[:template][:backgroundImage] = image_object
      rescue NoMethodError => e
        p "ERROR: #{e}: You need to add a Template before adding a background"
      end
    end

    def add_show_body_item(text_object: {}, image_object: {})
      begin
        @directives.first[:template][:image] = image_object
        self.directives[0][:template].merge!(text_object)
      rescue NoMethodError => e
         p "ERROR: #{e}: You need to add a Body Template before adding body content"
      end 
    end

    # To create Show lists, first create image and text objects and then add show list item.
    def add_show_list_item(
      token: '', 
      image_object: {},
      text_object: {}
      )
      self.directives[0][:template][:listItems] ||= []
      list_items = { 
        "token": token,
        "image": image_object,
        "textContent": text_object[:textContent]
      }
      begin
        self.directives[0][:template][:listItems] << list_items
      rescue NoMethodError => e
         p "ERROR: #{e}: You need to add a List Template before adding list content"
      end 
    end

    def create_show_text_object(
        primary_text: '',
        primary_text_type: "RichText",
        secondary_text: '',
        secondary_text_type: "RichText",
        tertiary_text: '',
        tertiary_text_type: "RichText"
      )
      {
        "textContent": {
          "primaryText": {
            "text": primary_text,
            "type": primary_text_type
          },
          "secondaryText": {
            "text": secondary_text,
            "type": secondary_text_type
          },
          "tertiaryText": {
            "text": tertiary_text,
            "type": tertiary_text_type
          }
        }
      }
    end
  end
# end<commit_msg>Update show_response.rb<commit_after>module AlexaWebService
  class ShowResponse
    attr_accessor :directives

    def initialize(type:, token:, title:, back_button:, background_image:, image:)
      @directives = [
        {
          "type": "Display.RenderTemplate",
          "template": {
            "type": type,
            "token": token,
            "backButton": back_button,
            "backgroundImage": background_image,
            "title": title,
            "image": image
          }
        }
      ]
    end

    def add_hint(hint_content)
      @directives << {
      "type": "Hint",
      "hint": {
        "type": "PlainText",
        "text": hint_content
        }
      }
    end

    def create_show_image_object(content_description = '', url = '')
      {
        "contentDescription": content_description,
        "sources": [
          {
            "url": url
          }
        ]
      }   
      
    end

    def add_background_image(image_object)
      begin
        @directives.first[:template][:backgroundImage] = image_object
      rescue NoMethodError => e
        p "ERROR: #{e}: You need to add a Template before adding a background"
      end
    end

    def add_show_body_item(text_object: {}, image_object: {})
      begin
        @directives.first[:template][:image] = image_object
        self.directives[0][:template].merge!(text_object)
      rescue NoMethodError => e
         p "ERROR: #{e}: You need to add a Body Template before adding body content"
      end 
    end

    # To create Show lists, first create image and text objects and then add show list item.
    def add_show_list_item(
      token: '', 
      image_object: {},
      text_object: {}
      )
      self.directives[0][:template][:listItems] ||= []
      list_items = { 
        "token": token,
        "image": image_object,
        "textContent": text_object[:textContent]
      }
      begin
        self.directives[0][:template][:listItems] << list_items
      rescue NoMethodError => e
         p "ERROR: #{e}: You need to add a List Template before adding list content"
      end 
    end

    def create_show_text_object(
        primary_text: '',
        primary_text_type: "RichText",
        secondary_text: '',
        secondary_text_type: "RichText",
        tertiary_text: '',
        tertiary_text_type: "RichText"
      )
      {
        "textContent": {
          "primaryText": {
            "text": primary_text,
            "type": primary_text_type
          },
          "secondaryText": {
            "text": secondary_text,
            "type": secondary_text_type
          },
          "tertiaryText": {
            "text": tertiary_text,
            "type": tertiary_text_type
          }
        }
      }
    end
  end
end
{'fraction_non_alphanumeric': 0.11028880866425993, 'fraction_numerical': 0.0010830324909747292, 'mean_word_length': 1.8547140649149922, 'pattern_counts': {'":': 56, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '352397', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1573, 'n_words': 361}