<commit_before>require 'cfpropertylist'

module SimCtl
  class DeviceSettings
    attr_reader :path

    def initialize(path)
      @path = path
    end

    # Disables the keyboard helpers
    #
    # @return [void]
    def disable_keyboard_helpers!
      edit_plist(path.preferences_plist) do |plist|
        %w(
          KeyboardAllowPaddle
          KeyboardAssistant
          KeyboardAutocapitalization
          KeyboardAutocorrection
          KeyboardCapsLock
          KeyboardCheckSpelling
          KeyboardPeriodShortcut
          KeyboardPrediction
          KeyboardShowPredictionBar
        ).each do |key|
          plist[key] = false
        end
      end
    end

    def edit_plist(path, &block)
      plist = File.exists?(path) ? CFPropertyList::List.new(file: path) : CFPropertyList::List.new
      content = CFPropertyList.native_types(plist.value) || {}
      yield content
      plist.value = CFPropertyList.guess(content)
      plist.save(path, CFPropertyList::List::FORMAT_BINARY)
    end

    # Sets the device language
    #
    # @return [void]
    def set_language(language)
      edit_plist(path.global_preferences_plist) do |plist|
        key = 'AppleLanguages'
        plist[key] = [] unless plist.has_key?(key)
        plist[key].unshift(language).uniq!
      end
    end
  end
end<commit_msg>Add update_hardware_keyboard!<commit_after>require 'cfpropertylist'

module SimCtl
  class DeviceSettings
    attr_reader :path

    def initialize(path)
      @path = path
    end

    # Disables the keyboard helpers
    #
    # @return [void]
    def disable_keyboard_helpers!
      edit_plist(path.preferences_plist) do |plist|
        %w(
          KeyboardAllowPaddle
          KeyboardAssistant
          KeyboardAutocapitalization
          KeyboardAutocorrection
          KeyboardCapsLock
          KeyboardCheckSpelling
          KeyboardPeriodShortcut
          KeyboardPrediction
          KeyboardShowPredictionBar
        ).each do |key|
          plist[key] = false
        end
      end
    end

    # Updates hardware keyboard settings
    #
    # @param enabled value to replace
    # @return [vod]
    def update_hardware_keyboard!(enabled)
      edit_plist(path.preferences_plist) do |plist|
        plist['AutomaticMinimizationEnabled'] = enabled
      end
    end

    def edit_plist(path, &block)
      plist = File.exists?(path) ? CFPropertyList::List.new(file: path) : CFPropertyList::List.new
      content = CFPropertyList.native_types(plist.value) || {}
      yield content
      plist.value = CFPropertyList.guess(content)
      plist.save(path, CFPropertyList::List::FORMAT_BINARY)
    end

    # Sets the device language
    #
    # @return [void]
    def set_language(language)
      edit_plist(path.global_preferences_plist) do |plist|
        key = 'AppleLanguages'
        plist[key] = [] unless plist.has_key?(key)
        plist[key].unshift(language).uniq!
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07861741782446628, 'fraction_numerical': 0.0, 'mean_word_length': 2.477031802120141, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1757086', 'n_tokens_mistral': 909, 'n_tokens_neox': 871, 'n_words': 180}