<commit_before>#!/usr/bin/ruby -w
require 'plist' # https://github.com/bleything/plist
require 'rexml/document'

# // Set Frame
# // Initializes a view frame inside a code block
# // Platform: All
# // Language: Objective-C
# // Completion Scope: Function or Method
# // [Codesnippet]

wkDir = Dir.getwd

Dir.chdir(Dir.home+"/Library/Developer/Xcode/UserData/CodeSnippets")

codeSnippetCompletionScopes = ""
codeSnippetContents = ""
codeSnippetIdentifier = ""
codeSnippetLanguage = ""
codeSnippetTitle = ""
codeSnippetUserSnippet = ""
codeSnippetVersion = ""

Dir.glob("*.codesnippet") do |snippetFilename|
  puts snippetFilename

  result = Plist::parse_xml(snippetFilename)

  # key : IDECodeSnippetCompletionScopes
  codeSnippetCompletionScopes = result['IDECodeSnippetCompletionScopes'][0]
  # key : IDECodeSnippetContents
  codeSnippetContents = result['IDECodeSnippetContents']
  # key : IDECodeSnippetIdentifier
  codeSnippetIdentifier = result['IDECodeSnippetIdentifier']
  # key : IDECodeSnippetLanguage
  codeSnippetLanguage = result['IDECodeSnippetLanguage']
  # key : IDECodeSnippetTitle
  codeSnippetTitle = result['IDECodeSnippetTitle']
  # key : IDECodeSnippetUserSnippet
  codeSnippetUserSnippet = result['IDECodeSnippetUserSnippet']
  # key : IDECodeSnippetVersion
  codeSnippetVersion = result['IDECodeSnippetVersion']

  filename = codeSnippetTitle.downcase.strip.gsub(/[^\w\.\-]/,"_")
  f = File.open(wkDir+"/"+filename.insert(-1,".m"),"w+")
  f.puts("// IDECodeSnippetTitle: #{codeSnippetTitle}")
  f.puts("// IDECodeSnippetCompletionScopes: #{codeSnippetCompletionScopes}")
  f.puts("// IDECodeSnippetLanguage: #{codeSnippetLanguage}")
  f.puts("#{codeSnippetContents}")

end
<commit_msg>Update script to extract and add snippets based on argument: extract or add. Add is not implemented.<commit_after>#!/usr/bin/ruby
require 'plist' # https://github.com/bleything/plist
require 'rexml/document'

# helper methods
# print message to console
def outputLogMessage(message)
  puts message
end

# // Set Frame
# // Initializes a view frame inside a code block
# // Platform: All
# // Language: Objective-C
# // Completion Scope: Function or Method
# // [Codesnippet]

startOptions = ARGV[0]

wkDir = Dir.getwd
xcodeDir = Dir.home+"/Library/Developer/Xcode/UserData/CodeSnippets"

if startOptions == "extract"
  outputLogMessage("Extracting snippets from #{xcodeDir}")

  Dir.chdir(xcodeDir)

  codeSnippetCompletionScopes = ""
  codeSnippetContents = ""
  codeSnippetIdentifier = ""
  codeSnippetLanguage = ""
  codeSnippetTitle = ""
  codeSnippetUserSnippet = ""
  codeSnippetVersion = ""

  Dir.glob("*.codesnippet") do |snippetFilename|
    # outputLogMessage(snippetFilename)

    result = Plist::parse_xml(snippetFilename)

    # key : IDECodeSnippetCompletionScopes
    codeSnippetCompletionScopes = result['IDECodeSnippetCompletionScopes'][0]
    # key : IDECodeSnippetContents
    codeSnippetContents = result['IDECodeSnippetContents']
    # key : IDECodeSnippetIdentifier
    codeSnippetIdentifier = result['IDECodeSnippetIdentifier']
    # key : IDECodeSnippetLanguage
    codeSnippetLanguage = result['IDECodeSnippetLanguage']
    # key : IDECodeSnippetTitle
    codeSnippetTitle = result['IDECodeSnippetTitle']
    # key : IDECodeSnippetUserSnippet
    codeSnippetUserSnippet = result['IDECodeSnippetUserSnippet']
    # key : IDECodeSnippetVersion
    codeSnippetVersion = result['IDECodeSnippetVersion']

    filename = codeSnippetTitle.downcase.strip.gsub(/[^\w\.\-]/,"_")
    f = File.open(wkDir+"/"+filename.insert(-1,".m"),"w+")
    f.puts("// IDECodeSnippetTitle: #{codeSnippetTitle}")
    f.puts("// IDECodeSnippetCompletionScopes: #{codeSnippetCompletionScopes}")
    f.puts("// IDECodeSnippetLanguage: #{codeSnippetLanguage}")
    f.puts("#{codeSnippetContents}")

  end
elsif startOptions == "add"
  outputLogMessage("Add snippets to #{xcodeDir}")
else
  outputLogMessage("Use xcode-snippets with 'extract' or 'add' argument")
end

{'fraction_non_alphanumeric': 0.12490556534877864, 'fraction_numerical': 0.0012591286829513977, 'mean_word_length': 5.235478806907379, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1418889', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1262, 'n_words': 226}