<commit_before># LinuxAdmin fstab Representation
#
# Copyright (C) 2013 Red Hat Inc.
# Licensed under the MIT License

require 'singleton'

class LinuxAdmin
  class FSTabEntry < LinuxAdmin
    attr_accessor :device
    attr_accessor :mount_point
    attr_accessor :fs_type
    attr_accessor :mount_options
    attr_accessor :dumpable
    attr_accessor :fsck_order
  end

  class FSTab < LinuxAdmin
    include Singleton

    attr_accessor :entries

    def initialize
      refresh
    end

    def write!
      content = ''
      @entries.each do |entry|
        content += "#{entry.device} #{entry.mount_point} #{entry.fs_type} #{entry.mount_options} #{entry.dumpable} #{entry.fsck_order}\n"
      end
      File.write('/etc/fstab', content)
      self
    end

    private

    def refresh
      @entries = []
      f = File.read('/etc/fstab')
      f.each_line { |line|
        first_char = line.strip[0] 
        if first_char != '#' && first_char !~ /\s/
          columns = line.split
          entry   = FSTabEntry.new
          entry.device         = columns[0]
          entry.mount_point    = columns[1]
          entry.fs_type        = columns[2]
          entry.mount_options  = columns[3]
          entry.dumpable       = columns[4].to_i
          entry.fsck_order     = columns[5].to_i
          @entries << entry
        end
      }
      self
    end
  end
end<commit_msg>code refactoring to simplify methods<commit_after># LinuxAdmin fstab Representation
#
# Copyright (C) 2013 Red Hat Inc.
# Licensed under the MIT License

require 'singleton'

class LinuxAdmin
  class FSTabEntry < LinuxAdmin
    attr_accessor :device
    attr_accessor :mount_point
    attr_accessor :fs_type
    attr_accessor :mount_options
    attr_accessor :dumpable
    attr_accessor :fsck_order

    def initialize(args = {})
      @device        = args[:device]
      @mount_point   = args[:mount_point]
      @fs_type       = args[:fs_type]
      @mount_options = args[:mount_options]
      @dumpable      = args[:dumpable]
      @fsck_order    = args[:fsck_order]
    end

    def self.from_line(fstab_line)
      columns = fstab_line.chomp.split
      FSTabEntry.new :device        => columns[0],
                     :mount_point   => columns[1],
                     :fs_type       => columns[2],
                     :mount_options => columns[3],
                     :dumpable      => columns[4].to_i,
                     :fsck_order    => columns[5].to_i
      
    end
  end

  class FSTab < LinuxAdmin
    include Singleton

    attr_accessor :entries

    def initialize
      refresh
    end

    def write!
      content = ''
      @entries.each do |entry|
        content += "#{entry.device} #{entry.mount_point} #{entry.fs_type} #{entry.mount_options} #{entry.dumpable} #{entry.fsck_order}\n"
      end
      File.write('/etc/fstab', content)
      self
    end

    private

    def read
      contents = File.read('/etc/fstab')
      contents = contents.lines.to_a
      contents.reject! { |line|
        first_char = line.strip[0]
        first_char == '#' || first_char =~ /\s/
      }
      contents
    end

    def refresh
      @entries = 
        read.collect { |line|
          FSTabEntry.from_line line
        }
    end
  end
end
{'fraction_non_alphanumeric': 0.09781605659796985, 'fraction_numerical': 0.00676714856967087, 'mean_word_length': 2.01949860724234, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5866782', 'n_tokens_mistral': 1039, 'n_tokens_neox': 998, 'n_words': 227}