Class: Git::DirstatInfo Private
- Inherits:
-
Data
- Object
- Data
- Git::DirstatInfo
- Includes:
- Enumerable
- Defined in:
- lib/git/dirstat_info.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Immutable result object from git --dirstat output
Contains the list of directories and their contribution percentages to the diff.
Work in progress; this class is internal for now and may be made public in a future release.
Instance Attribute Summary collapse
-
#entries ⇒ Array<DirstatEntry>
readonly
Directory statistics in order from git output.
Instance Method Summary collapse
-
#[](directory) ⇒ Float?
private
Look up percentage by directory path.
-
#each(&block)
private
Iterate over entries.
-
#empty? ⇒ Boolean
private
Check if dirstat is empty.
-
#size ⇒ Integer
private
Number of directories in the dirstat.
-
#to_h ⇒ Hash<String, Float>
private
Convert to a Hash mapping directory to percentage.
Instance Attribute Details
#entries ⇒ Array<DirstatEntry> (readonly)
Returns directory statistics in order from git output.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/git/dirstat_info.rb', line 45 DirstatInfo = Data.define(:entries) do # Look up percentage by directory path # # @param directory [String] the directory path # # @return [Float, nil] the percentage or nil if not found # def [](directory) entries.find { |e| e.directory == directory }&.percentage end # Convert to a Hash mapping directory to percentage # # @return [Hash<String, Float>] # def to_h entries.to_h { |e| [e.directory, e.percentage] } end # Number of directories in the dirstat # # @return [Integer] # def size entries.size end # Check if dirstat is empty # # @return [Boolean] # def empty? entries.empty? end # Iterate over entries # # @overload each # # @return [Enumerator<Git::DirstatEntry>] an enumerator over all dirstat entries # # @overload each(&block) # # @return [Array<Git::DirstatEntry>] the full list of dirstat entries # # @yield [entry] each dirstat entry # # @yieldparam entry [Git::DirstatEntry] a single dirstat entry # # @yieldreturn [void] # def each(&block) entries.each(&block) end include Enumerable end |
Instance Method Details
#[](directory) ⇒ Float?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Look up percentage by directory path
52 53 54 |
# File 'lib/git/dirstat_info.rb', line 52 def [](directory) entries.find { |e| e.directory == directory }&.percentage end |
#each ⇒ Enumerator<Git::DirstatEntry> #each {|entry| ... } ⇒ Array<Git::DirstatEntry>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Iterate over entries
96 97 98 |
# File 'lib/git/dirstat_info.rb', line 96 def each(&block) entries.each(&block) end |
#empty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if dirstat is empty
76 77 78 |
# File 'lib/git/dirstat_info.rb', line 76 def empty? entries.empty? end |
#size ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Number of directories in the dirstat
68 69 70 |
# File 'lib/git/dirstat_info.rb', line 68 def size entries.size end |
#to_h ⇒ Hash<String, Float>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Convert to a Hash mapping directory to percentage
60 61 62 |
# File 'lib/git/dirstat_info.rb', line 60 def to_h entries.to_h { |e| [e.directory, e.percentage] } end |