<commit_before>module SoFarSoGood
  class Clauses
    class << self

      HEADINGS = ["Clause", "Description"]

      def numbers(exclude_reserved=false)
        @numbers ||= clauses(exclude_reserved).map { |c| c.number }
      end

      def subjects(exclude_reserved=false)
        @subjects ||= clauses(exclude_reserved).map { |c| c.subject }
      end
      alias_method :descriptions, :subjects

      def clauses(exclude_reserved = false)
        @clauses ||= begin
          clauses = sections.map { |node| SoFarSoGood::Clause.new(node) }
          clauses.select { |c| !c.reserved } if exclude_reserved
          clauses
        end
      end
      alias_method :list, :clauses

      def to_md
        @md ||= Terminal::Table.new(:rows => rows, :style => { :border_i => "|" }, :headings => HEADINGS).to_s
      end

      def to_json
        @json ||= sections.to_json
      end

      def [](number)
        clauses.find { |c| c.number == number }
      end

      private

      def source_path
        File.expand_path "CFR-2010-title48-vol2-chap1-subchapH.xml", SoFarSoGood.vendor_directory
      end

      def doc
        @doc ||= Nokogiri::XML(File.open(source_path)) do |config|
          config.noblanks.nonet
        end
      end

      def sections
        @subpart ||= doc.css("PART SUBPART")[4].children.css("SECTION")
      end

      def rows
        @rows ||= clauses.reject { |c| c.reserved }.map { |c| [c.number, c.subject]}
      end
    end
  end
end
<commit_msg>proper json<commit_after>module SoFarSoGood
  class Clauses
    class << self

      HEADINGS = ["Clause", "Description"]

      def numbers(exclude_reserved=false)
        @numbers ||= clauses(exclude_reserved).map { |c| c.number }
      end

      def subjects(exclude_reserved=false)
        @subjects ||= clauses(exclude_reserved).map { |c| c.subject }
      end
      alias_method :descriptions, :subjects

      def clauses(exclude_reserved = false)
        @clauses ||= begin
          clauses = sections.map { |node| SoFarSoGood::Clause.new(node) }
          clauses.select { |c| !c.reserved } if exclude_reserved
          clauses
        end
      end
      alias_method :list, :clauses

      def to_md
        @md ||= Terminal::Table.new(:rows => rows, :style => { :border_i => "|" }, :headings => HEADINGS).to_s
      end

      def to_json
        @json ||= clauses.to_json
      end

      def [](number)
        clauses.find { |c| c.number == number }
      end

      private

      def source_path
        File.expand_path "CFR-2010-title48-vol2-chap1-subchapH.xml", SoFarSoGood.vendor_directory
      end

      def doc
        @doc ||= Nokogiri::XML(File.open(source_path)) do |config|
          config.noblanks.nonet
        end
      end

      def sections
        @subpart ||= doc.css("PART SUBPART")[4].children.css("SECTION")
      end

      def rows
        @rows ||= clauses.reject { |c| c.reserved }.map { |c| [c.number, c.subject]}
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.12261306532663317, 'fraction_numerical': 0.006030150753768844, 'mean_word_length': 2.156448202959831, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2619836', 'n_tokens_mistral': 1018, 'n_tokens_neox': 941, 'n_words': 209}