<commit_before>require "primix"

class Json < Primix::Annotation
  self.command = "jsoncop"

  def generate!
"""extension #{meta.name} {
    static func parse(json: Any) -> #{meta.name}? {
        guard let json = json as? [String: Any] else { return nil }
        guard #{json_extraction_lists.join(",\n\t\t")} else { return nil }
        return #{meta.name}()
    }
}"""
  end

  private

end<commit_msg>Fixed conflict in json<commit_after>require "primix"

class Json < Primix::Annotation
  self.command = "jsoncop"

  def generate!
"""extension #{meta.name} {
    static func parse(json: Any) -> #{meta.name}? {
        guard let json = json as? [String: Any] else { return nil }
        guard #{json_extraction_lists.join(",\n\t\t")} else { return nil }
        return #{meta.name}(#{meta.attributes.map { |a| "#{a.name}: #{a.name}" }.join(", ") })
    }
}"""
  end

  private

  def json_extraction_lists
    meta.attributes.map do |attr|
      "let #{attr.name} = json[\"#{attr.name}\"] as? #{attr.typename}"
    end
  end
end
{'fraction_non_alphanumeric': 0.17424975798644723, 'fraction_numerical': 0.0, 'mean_word_length': 3.0708661417322833, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6457793', 'n_tokens_mistral': 352, 'n_tokens_neox': 349, 'n_words': 90}