<commit_before>module FbUtils
  class Comment
    LINK = "http://graph.facebook.com/comments/?ids="

    attr_accessor :id, :message, :created_time, :from_name, :from_id

    def initialize(hash={})
      return if hash.empty?
      @id = hash["id"]
      @from_name = hash["from"]["name"]
      @from_id = hash["from"]["id"]
      @message = hash["message"]
      @created_time = hash["created_time"]
    end

    def to_s
      to_array.join(' ')
    end

    def to_array
      [@id, @message, @from_name, @from_id, @created_time]
    end

    # Get comments and save those in file system
    #
    # The rightmost argument is an optional hash of options, 
    # which is pass further to exact writer, deduced from :format key
    # Default is: :format => 'txt'
    #
    # For example: 
    #
    #   FbUtils::Comment.save('http://www.example.com', 'example_com')
    #
    #   FbUtils::Comment.save('http://www.example.com', 'example_com',
    #     :format => :csv,
    #     :fields_terminated_by => ";", 
    #     :fields_enclosed_by => "'", 
    #     :lines_terminated_by => "\n"
    def self.save(href, filename, *args)
      options = args.extract_options!
      options[:format] ||= "txt"

      comments = get(href)
      writer = "FbUtils::Writer::#{options[:format].to_s.camelize}".constantize.new(filename, options)
      writer.write(comments)
      comments
    end

    # Get comments related to href
    # Return array of comments<commit_msg>correct code comments<commit_after>module FbUtils
  class Comment
    LINK = "http://graph.facebook.com/comments/?ids="

    attr_accessor :id, :message, :created_time, :from_name, :from_id

    def initialize(hash={})
      return if hash.empty?
      @id = hash["id"]
      @from_name = hash["from"]["name"]
      @from_id = hash["from"]["id"]
      @message = hash["message"]
      @created_time = hash["created_time"]
    end

    def to_s
      to_array.join(' ')
    end

    def to_array
      [@id, @message, @from_name, @from_id, @created_time]
    end

    # Get comments and save these in file system
    #
    # The rightmost argument is an optional hash of options, 
    # which is pass further to particular writer, specified from :format key
    # Default is: :format => 'txt'
    #
    # For example: 
    #
    #   FbUtils::Comment.save('http://www.example.com', 'example_com')
    #
    #   FbUtils::Comment.save('http://www.example.com', 'example_com',
    #     :format => :csv,
    #     :fields_terminated_by => ";", 
    #     :fields_enclosed_by => "'", 
    #     :lines_terminated_by => "\n"
    def self.save(href, filename, *args)
      options = args.extract_options!
      options[:format] ||= "txt"

      comments = get(href)
      writer = "FbUtils::Writer::#{options[:format].to_s.camelize}".constantize.new(filename, options)
      writer.write(comments)
      comments
    end

    # Get comments related to href
    # Return array of comments
{'fraction_non_alphanumeric': 0.14271151885830785, 'fraction_numerical': 0.0, 'mean_word_length': 2.721871049304678, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2723564', 'n_tokens_mistral': 962, 'n_tokens_neox': 942, 'n_words': 219}