<commit_before>//  Copyright © 2016 <NAME>. All rights reserved.

import UIKit

final class WeatherView: UIView {

  enum Theme {
    case blistering
    case hot
    case neutral
    case cold

    fileprivate var gradientColors: (top: UIColor, bottom: UIColor) {
      switch self {
      case .blistering:
        return (.init(rgb: (254, 229, 207)), .init(rgb: (253, 191, 132)))
      case .hot:
        return (.init(rgb: (254, 212, 171)), .init(rgb: (255, 240, 233)))
      case .neutral:
        return (.init(rgb: (226, 232, 254)), .init(rgb: (255, 249, 255)))
      case .cold:
        return (.init(rgb: (255, 249, 255)), .init(rgb: (226, 232, 254)))
      }
    }
  }

  private var gradient: CAGradientLayer?

  var theme: Theme? {

    didSet {

      let animation: (() -> Void)

      if let theme = theme {
        let colors: (top: UIColor, bottom: UIColor) = theme.gradientColors
        animation = {
          let gradient: CAGradientLayer = CAGradientLayer()
          gradient.frame = self.layer.frame
          gradient.colors = [colors.top.cgColor, colors.bottom.cgColor]

          self.gradient = gradient
          self.layer.insertSublayer(gradient, at: 0)
          self.backgroundColor = nil
        }
      } else {
        animation = {
          self.gradient?.removeFromSuperlayer()
          self.gradient = nil
          self.backgroundColor = .white
        }
      }

      UIView.transition(with: self, duration: 0.5, options: [.curveLinear], animations: animation)

    }

  }

  override static var layerClass: AnyClass { return CAGradientLayer.self }

}

fileprivate extension UIColor {

  convenience init(rgb: (Int, Int, Int), alpha: CGFloat = 1.0) {
    let red: CGFloat = CGFloat(rgb.0) / 255.0
    let green: CGFloat = CGFloat(rgb.1) / 255.0
    let blue: CGFloat = CGFloat(rgb.2) / 255.0

    self.init(red: red, green: green, blue: blue, alpha: alpha)
  }

}<commit_msg>Create a new Animation Layer in the case there wasn't one to begin with<commit_after>//  Copyright © 2016 <NAME>. All rights reserved.

import UIKit

final class WeatherView: UIView {

  enum Theme {
    case blistering
    case hot
    case neutral
    case cold

    fileprivate var gradientColors: (top: UIColor, bottom: UIColor) {
      switch self {
      case .blistering:
        return (.init(rgb: (254, 229, 207)), .init(rgb: (253, 191, 132)))
      case .hot:
        return (.init(rgb: (254, 212, 171)), .init(rgb: (255, 240, 233)))
      case .neutral:
        return (.init(rgb: (226, 232, 254)), .init(rgb: (255, 249, 255)))
      case .cold:
        return (.init(rgb: (255, 249, 255)), .init(rgb: (226, 232, 254)))
      }
    }
  }

  private var gradient: CAGradientLayer?

  var theme: Theme? {

    didSet {

      let animation: (() -> Void)

      if let theme = theme {

        let colors: (top: UIColor, bottom: UIColor) = theme.gradientColors

        if let existing: CAGradientLayer = gradient {
          animation = {
            existing.colors = [colors.top.cgColor, colors.bottom.cgColor]
          }
        } else {
          animation = {
            let gradient: CAGradientLayer = CAGradientLayer()
            gradient.frame = self.layer.frame
            gradient.colors = [colors.top.cgColor, colors.bottom.cgColor]

            self.gradient = gradient
            self.layer.insertSublayer(gradient, at: 0)
            self.backgroundColor = nil
          }
        }

      } else {

        DispatchQueue.main.async {
          self.backgroundColor = .white
        }

        animation = {
          self.gradient?.removeFromSuperlayer()
          self.gradient = nil
        }

      }

      UIView.transition(with: self, duration: 0.5, options: [.curveLinear], animations: animation)

    }

  }

  override static var layerClass: AnyClass { return CAGradientLayer.self }

}

fileprivate extension UIColor {

  convenience init(rgb: (Int, Int, Int), alpha: CGFloat = 1.0) {
    let red: CGFloat = CGFloat(rgb.0) / 255.0
    let green: CGFloat = CGFloat(rgb.1) / 255.0
    let blue: CGFloat = CGFloat(rgb.2) / 255.0

    self.init(red: red, green: green, blue: blue, alpha: alpha)
  }

}
{'fraction_non_alphanumeric': 0.12301396244583535, 'fraction_numerical': 0.046220510351468465, 'mean_word_length': 2.2084942084942085, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7472532', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1291, 'n_words': 368}