<commit_before>module Cocoatree
  class Pod
    attr_reader :spec

    def initialize spec
      @spec = spec
    end

    def method_missing method_name, *args
      if spec.respond_to? method_name
        spec.send(method_name, *args)
      end
    end

    def url
      spec.source[:git]
    end

    def github?
      !github_data.empty?
    end

    def github
      github_data.join '/'
    end

    def stars
      @stars ||= (fetch_stars || -1)
    end

  private

    def fetch_stars
      data = Cocoatree.github_cache.fetch(github) do
        Octokit.repository(github)
      end
      data['watchers_count'] if data
    rescue  Octokit::BadRequest,
            Octokit::Unauthorized,
            Octokit::Forbidden,
            Octokit::NotFound,
            Octokit::NotAcceptable,
            Octokit::UnprocessableEntity,
            Octokit::InternalServerError,
            Octokit::NotImplemented,
            Octokit::BadGateway,
            Octokit::ServiceUnavailable => e
      p e
      nil
    end

    def github_data
      matchdata = /github.com\/(.+)\/(.+).git/.match url
      return [] unless matchdata
      matchdata.captures
    end
  end
end<commit_msg>Refactor pod<commit_after>module Cocoatree
  class Pod
    attr_reader :spec

    def initialize spec
      @spec = spec
    end

    def method_missing method_name, *args
      if spec.respond_to? method_name
        spec.send(method_name, *args)
      end
    end

    def url
      spec.source[:git]
    end

    def github?
      !github_data.empty?
    end

    def github
      github_data.join '/'
    end

    def stars
      @stars ||= (fetch_stars || -1)
    end

  private

    def fetch_stars
      data = fetch_github_repository_data
      data['watchers_count'] if data
    end

    def github_data
      matchdata = /github.com\/(.+)\/(.+).git/.match url
      return [] unless matchdata
      matchdata.captures
    end

    def fetch_github_repository_data
      Cocoatree.github_cache.fetch(github) do
        Octokit.repository(github)
      end
    rescue  Octokit::BadRequest,
            Octokit::Unauthorized,
            Octokit::Forbidden,
            Octokit::NotFound,
            Octokit::NotAcceptable,
            Octokit::UnprocessableEntity,
            Octokit::InternalServerError,
            Octokit::NotImplemented,
            Octokit::BadGateway,
            Octokit::ServiceUnavailable => e
      p e
      nil
    end
  end
end
{'fraction_non_alphanumeric': 0.08143322475570032, 'fraction_numerical': 0.0008143322475570033, 'mean_word_length': 1.914590747330961, 'pattern_counts': {'":': 0, '<': 3, '<?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': '193736', 'n_tokens_mistral': 778, 'n_tokens_neox': 741, 'n_words': 164}