<commit_before>module JekyllImport
  module Importers
    class Behance < Importer
      def self.require_deps
        JekyllImport.require_with_fallback(%w[
          fileutils
          safe_yaml
          date
          time
          behance
        ])
      end

      def self.specify_options(c)
        c.option 'user', '--user NAME', 'The username of the account'
        c.option 'api_token', '--api_token TOKEN', 'The API access token for the account'
      end

      def self.validate(options)
        %w[user api_token].each do |option|
          if options[option].nil?
            abort "Missing mandatory option --#{option}."
          end
        end
      end

      # Process the import.
      #
      # user - the behance user to retrieve projects (ID or username)
      # api_token - your developer API Token
      #
      # Returns nothing.
      def self.process(options)
        validate(options)

        user  = options[:user]
        token = options[:api_token]

        client    = Behance::Client.new(access_token: token)
        projects  = client.user_projects(user)

        puts "#{projects.length} project(s) found. Importing now..."

        projects.each do |project|

          details = client.project(project['id'])
          title   = project['name'].to_s
          formatted_date = Time.at(project['published_on'].to_i).to_date.to_s

          post_name = title.split(%r{ |!|/|:|&|-|$|,}).map do |character|
            character.downcase unless character.empty?
          end.compact.join('-')

          name = "#{formatted_date}-#{post_name}"

          header = {
            "layout" => "post",
            "title" => title,
            "project" => details
          }

          FileUtils.mkdir_p("_posts")

          File.open("_posts/#{name}.md", "w") do |f|
            f.puts header.to_yaml
            f.puts "---\n\n"
            f.puts details['description']
          end
        end

        puts "Finished importing."
      end
    end
  end
end<commit_msg>Minor refactor to Behance importer<commit_after>module JekyllImport
  module Importers
    class Behance < Importer
      def self.require_deps
        JekyllImport.require_with_fallback(%w[
          fileutils
          safe_yaml
          date
          time
          behance
        ])
      end

      def self.specify_options(c)
        c.option 'user', '--user NAME', 'The username of the account'
        c.option 'api_token', '--api_token TOKEN', 'The API access token for the account'
      end

      def self.validate(options)
        %w[user api_token].each do |option|
          if options[option].nil?
            abort "Missing mandatory option --#{option}."
          end
        end
      end

      # Process the import.
      #
      # user - the behance user to retrieve projects (ID or username)
      # api_token - your developer API Token
      #
      # Returns nothing.
      def self.process(options)
        user  = options.fetch('user')
        token = options.fetch('api_token')

        projects = fetch_projects(token, user)

        puts "#{projects.length} project(s) found. Importing now..."

        projects.each do |project|

          details = client.project(project['id'])
          title   = project['name'].to_s
          formatted_date = Time.at(project['published_on'].to_i).to_date.to_s

          post_name = title.split(%r{ |!|/|:|&|-|$|,}).map do |character|
            character.downcase unless character.empty?
          end.compact.join('-')

          name = "#{formatted_date}-#{post_name}"

          header = {
            "layout" => "post",
            "title" => title,
            "project" => details
          }

          FileUtils.mkdir_p("_posts")

          File.open("_posts/#{name}.md", "w") do |f|
            f.puts header.to_yaml
            f.puts "---\n\n"
            f.puts details['description']
          end
        end

        puts "Finished importing."
      end

      private

      def self.fetch_projects(token, user)
        Behance::Client.new(access_token: token).user_projects(user)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11567436208991494, 'fraction_numerical': 0.0, 'mean_word_length': 1.7661290322580645, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '657114', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1188, 'n_words': 287}