<commit_before>//
//  AnimalResponseMapper.swift
//  TOZ_iOS
//
//  Copyright © 2017 intive. All rights reserved.
//

import Foundation

/**
 Parses response from OrganizationInfo operation. Inherits from generic ResponseMapper class.
 */
final class AnimalResponseMapper: ResponseMapper<AnimalItem>, ResponseMapperProtocol {
    // swiftlint:disable cyclomatic_complexity
    static func process(_ obj: AnyObject?) throws -> AnimalItem {
        return try process(obj, parse: { json in
            guard let animalID = json["id"] as? String else { return nil }
            guard let name = json["name"] as? String else { return nil }
            guard let type = json["type"] as? String else { return nil }
            guard let sex = json["sex"] as? String else { return nil }
            guard let description = json["description"] as? String? else { return nil }
            guard let address = json["address"] as? String? else { return nil }
            guard let createdInt = json["created"] as? Int? else { return nil }
            var createdDate: Date? = nil
            if let createdInt = createdInt {
                createdDate = Date(timeIntervalSince1970: TimeInterval(createdInt/1000))
            }
            guard let lastModified = json["lastModified"] as? Int? else { return nil }
            var lastModifiedDate: Date? = nil
            if let lastModified = lastModified {
                lastModifiedDate = Date(timeIntervalSince1970: TimeInterval(lastModified/1000))
            }
            guard let imageString = json["imageUrl"] as? String? else { return nil }
            var imageURL: URL? = nil
            if let imageString = imageString {
                imageURL = BackendConfiguration.shared.photosURL.appendingPathComponent(imageString)
            }
            return AnimalItem(animalID: animalID, name: name, type: type, sex: sex, description: description, address: address, created: createdDate, lastModified: lastModifiedDate, imageUrl: imageURL)
        })
    }
}<commit_msg>Map gallery from backend to array of URLs<commit_after>//
//  AnimalResponseMapper.swift
//  TOZ_iOS
//
//  Copyright © 2017 intive. All rights reserved.
//

import Foundation

/**
 Parses response from OrganizationInfo operation. Inherits from generic ResponseMapper class.
 */
final class AnimalResponseMapper: ResponseMapper<AnimalItem>, ResponseMapperProtocol {
    // swiftlint:disable cyclomatic_complexity
    static func process(_ obj: AnyObject?) throws -> AnimalItem {
        return try process(obj, parse: { json in
            guard let animalID = json["id"] as? String else { return nil }
            guard let name = json["name"] as? String else { return nil }
            guard let type = json["type"] as? String else { return nil }
            guard let sex = json["sex"] as? String else { return nil }
            guard let description = json["description"] as? String? else { return nil }
            guard let address = json["address"] as? String? else { return nil }
            guard let createdInt = json["created"] as? Int? else { return nil }
            var createdDate: Date? = nil
            if let createdInt = createdInt {
                createdDate = Date(timeIntervalSince1970: TimeInterval(createdInt/1000))
            }
            guard let lastModified = json["lastModified"] as? Int? else { return nil }
            var lastModifiedDate: Date? = nil
            if let lastModified = lastModified {
                lastModifiedDate = Date(timeIntervalSince1970: TimeInterval(lastModified/1000))
            }
            guard let imageString = json["imageUrl"] as? String? else { return nil }
            var imageURL: URL? = nil
            if let imageString = imageString {
                imageURL = BackendConfiguration.shared.photosURL.appendingPathComponent(imageString)
            }
            guard let gallery = json["gallery"] as? [AnimalGalleryItem]? else { return nil }
            var galleryURLs: [URL] = []
            if let gallery = gallery {
                for item in gallery {
                    galleryURLs.append(BackendConfiguration.shared.photosURL.appendingPathComponent(item.fileUrl))
                }
            }
            return AnimalItem(animalID: animalID, name: name, type: type, sex: sex, description: description, address: address, created: createdDate, lastModified: lastModifiedDate, imageUrl: imageURL, galleryURLs: galleryURLs)
        })
    }
}
{'fraction_non_alphanumeric': 0.0894418291862811, 'fraction_numerical': 0.008966599417171038, 'mean_word_length': 2.4804992199687987, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '503152', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1078, 'n_words': 378}