Skip to content

Instantly share code, notes, and snippets.

@terotil
Created March 6, 2012 06:49
Show Gist options
  • Save terotil/1984406 to your computer and use it in GitHub Desktop.
Save terotil/1984406 to your computer and use it in GitHub Desktop.
which approach is better?
class Stat
def initialize(raw)
@raw = raw
end
def file
@file ||= parse_file_from_raw
end
def name
@file ||= parse_name_from_raw
end
private
# parsing thingies
end
@sent-hil
Copy link

sent-hil commented Mar 6, 2012

  class Repo
    attr_reader :commits, :log

    def initialize(path)
      @path = path
      @log  = raw_log

      string  = remove_tabs(@log)
      split   = split_commits_by_marker(string)
      commits = create_commits(split)

      @commits = commits
    end

    def remove_tabs(str)
      str.gsub(/\t/, " ")
    end

    def split_commits_by_marker(str)
      str.split('$$')
      str.delete("")

      str
    end

    def create_commits(commits)
      commits.map do |commit|
        Commit.new(commit)
      end
    end

    def raw_log
      Dir.chdir(@path) do
        `git log --format='$$^^%h^^%ct^^%B' --numstat`
      end
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment