<commit_before>module Bibliothecary
  module Parsers
    class Swift
      include Bibliothecary::Analyser

      def self.parse(filename, path)
        if filename.match(/^Package\.swift$/i)
          file_contents = File.open(path).read
          parse_package_swift(file_contents)
        else
          []
        end
      end

      def self.parse_package_swift(manifest)
        response = Typhoeus.post("http://192.241.154.173/to-json", body: manifest)
        json = JSON.parse(response.body)
        json["dependencies"].map do |dependency|
          name = dependency['url'].gsub(/^https?:\/\//, '').gsub(/\.git$/,'')
          version = "#{dependency['version']['lowerBound']} - #{dependency['version']['upperBound']}"<commit_msg>Switch swift parsing ip to domain name<commit_after>module Bibliothecary
  module Parsers
    class Swift
      include Bibliothecary::Analyser

      def self.parse(filename, path)
        if filename.match(/^Package\.swift$/i)
          file_contents = File.open(path).read
          parse_package_swift(file_contents)
        else
          []
        end
      end

      def self.parse_package_swift(manifest)
        response = Typhoeus.post("http://swiftpm.honza.tech/to-json", body: manifest)
        json = JSON.parse(response.body)
        json["dependencies"].map do |dependency|
          name = dependency['url'].gsub(/^https?:\/\//, '').gsub(/\.git$/,'')
          version = "#{dependency['version']['lowerBound']} - #{dependency['version']['upperBound']}"
{'fraction_non_alphanumeric': 0.15145502645502645, 'fraction_numerical': 0.007936507936507936, 'mean_word_length': 2.637019230769231, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '2536241', 'n_tokens_mistral': 469, 'n_tokens_neox': 436, 'n_words': 77}