<commit_before>import Foundation

@objc(FabricAnswers)
class FabricAnswers: CDVPlugin {
    private func frame(command: CDVInvokedUrlCommand, _ proc: (Dictionary<String, AnyObject>?, Dictionary<String, AnyObject>?) -> Void) {
        let dict = command.arguments.first.flatMap { $0 as? Dictionary<String, AnyObject> }
        let custom = dict?["custom"] as? Dictionary<String, AnyObject>
        
        proc(dict, custom)
        commandDelegate!.sendPluginResult(CDVPluginResult(status: CDVCommandStatus_OK), callbackId: command.callbackId)
    }
    
    func eventPurchase(command: CDVInvokedUrlCommand) {
        frame(command) { dict, custom in
            let price = (dict?["itemPrice"]?.doubleValue).map { NSDecimalNumber(double: $0) }
            let currency = dict?["currency"] as? String
            let success = (dict?["success"] as? Bool).map { $0 ? 1 : 0 }
            let name = dict?["itemName"] as? String
            let type = dict?["itemType"] as? String
            let id = dict?["itemId"] as? String
            Answers.logPurchaseWithPrice(price, currency: currency, success: success, itemName: name, itemType: type, itemId: id, customAttributes: custom)
        }
    }
    
    func eventAddToCart(command: CDVInvokedUrlCommand) {
        frame(command) { dict, custom in
            let price = (dict?["itemPrice"] as? NSNumber).map { NSDecimalNumber(decimal: $0.decimalValue) }
            let currency = dict?["currency"] as? String
            let name = dict?["itemName"] as? String
            let type = dict?["itemType"] as? String
            let id = dict?["itemId"] as? String
            Answers.logAddToCartWithPrice(price, currency: currency, itemName: name, itemType: type, itemId: id, customAttributes: custom)
        }
    }
    
    func eventStartCheckout(command: CDVInvokedUrlCommand) {
        frame(command) { dict, custom in
            let price = (dict?["totalPrice"] as? NSNumber).map { NSDecimalNumber(decimal: $0.decimalValue) }
            let currency = dict?["currency"] as? String
            let count = dict?["itemCount"] as? NSNumber
            Answers.logStartCheckoutWithPrice(price, currency: currency, itemCount: count, customAttributes: custom)
        }
    }<commit_msg>数値を StringInterpolation で解析<commit_after>import Foundation

@objc(FabricAnswers)
class FabricAnswers: CDVPlugin {
    private func frame(command: CDVInvokedUrlCommand, _ proc: (Dictionary<String, AnyObject>?, Dictionary<String, AnyObject>?) -> Void) {
        let dict = command.arguments.first.flatMap { $0 as? Dictionary<String, AnyObject> }
        let custom = dict?["custom"] as? Dictionary<String, AnyObject>
        
        proc(dict, custom)
        commandDelegate!.sendPluginResult(CDVPluginResult(status: CDVCommandStatus_OK), callbackId: command.callbackId)
    }
    
    func eventPurchase(command: CDVInvokedUrlCommand) {
        frame(command) { dict, custom in
            let price = dict?["itemPrice"].map { NSDecimalNumber(string: "\($0)") }
            let currency = dict?["currency"] as? String
            let success = (dict?["success"] as? Bool).map { $0 ? 1 : 0 }
            let name = dict?["itemName"] as? String
            let type = dict?["itemType"] as? String
            let id = dict?["itemId"] as? String
            Answers.logPurchaseWithPrice(price, currency: currency, success: success, itemName: name, itemType: type, itemId: id, customAttributes: custom)
        }
    }
    
    func eventAddToCart(command: CDVInvokedUrlCommand) {
        frame(command) { dict, custom in
            let price = (dict?["itemPrice"] as? NSNumber).map { NSDecimalNumber(decimal: $0.decimalValue) }
            let currency = dict?["currency"] as? String
            let name = dict?["itemName"] as? String
            let type = dict?["itemType"] as? String
            let id = dict?["itemId"] as? String
            Answers.logAddToCartWithPrice(price, currency: currency, itemName: name, itemType: type, itemId: id, customAttributes: custom)
        }
    }
    
    func eventStartCheckout(command: CDVInvokedUrlCommand) {
        frame(command) { dict, custom in
            let price = (dict?["totalPrice"] as? NSNumber).map { NSDecimalNumber(decimal: $0.decimalValue) }
            let currency = dict?["currency"] as? String
            let count = dict?["itemCount"] as? NSNumber
            Answers.logStartCheckoutWithPrice(price, currency: currency, itemCount: count, customAttributes: custom)
        }
    }
{'fraction_non_alphanumeric': 0.1181049822064057, 'fraction_numerical': 0.003113879003558719, 'mean_word_length': 2.969108561341571, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '5699038', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1290, 'n_words': 330}