Class | Ohcount::LocList
In: | lib/ohcount/loc_list.rb
Parent: | Object

Tracks total lines of code, comments, and blanks for multiple languages

### Methods

+ add_loc add_loc_delta add_loc_delta_list add_loc_list blanks code comments compact filecount languages loc method_missing new total

### Attributes

locs | [RW] |

### Public Class methods

new(locs=[])

[Source]

    # File lib/ohcount/loc_list.rb, line 6
                    def initialize(locs=[])
                            @locs = locs
                    end

### Public Instance methods

+(addend)

[Source]

    # File lib/ohcount/loc_list.rb, line 18
                    def +(addend)
                            case addend
                            when Loc
                                    add_loc(addend)
                            when LocList
                                    add_loc_list(addend)
                            when LocDelta
                                    add_loc_delta(addend)
                            when LocDeltaList
                                    add_loc_delta_list(addend)
                            else
                                    raise ArgumentError.new
                            end
                            self
                    end

add_loc(addend)

[Source]

    # File lib/ohcount/loc_list.rb, line 39
                    def add_loc(addend)
                            existing = loc(addend.language)
                            if existing
                                    existing += addend
                            else
                                    @locs << addend
                            end
                            self
                    end

add_loc_delta(addend)

[Source]

    # File lib/ohcount/loc_list.rb, line 49
                    def add_loc_delta(addend)
                            l = loc(addend.language)
                            unless l
                                    l = Loc.new(addend.language)
                                    @locs << l
                            end
                            l.code += addend.code_added - addend.code_removed
                            l.comments += addend.comments_added - addend.comments_removed
                            l.blanks += addend.blanks_added - addend.blanks_removed
                            self
                    end

add_loc_delta_list(addend)

[Source]

    # File lib/ohcount/loc_list.rb, line 61
                    def add_loc_delta_list(addend)
                            addend.loc_deltas.each { |d| add_loc_delta(d) }
                    end

add_loc_list(addend)

[Source]

    # File lib/ohcount/loc_list.rb, line 34
                    def add_loc_list(addend)
                            addend.locs.each { |loc| add_loc(loc) }
                            self
                    end

blanks()

[Source]

    # File lib/ohcount/loc_list.rb, line 73
                    def blanks
                            @locs.inject(0) { |sum, loc| sum + loc.blanks }
                    end

code()

[Source]

    # File lib/ohcount/loc_list.rb, line 65
                    def code
                            @locs.inject(0) { |sum, loc| sum + loc.code }
                    end

comments()

[Source]

    # File lib/ohcount/loc_list.rb, line 69
                    def comments
                            @locs.inject(0) { |sum, loc| sum + loc.comments }
                    end

compact()

Returns a new loc_list excluding all languages with 0 lines

[Source]

    # File lib/ohcount/loc_list.rb, line 86
                    def compact
                            LocList.new(@locs.reject { |loc| loc.total == 0 })
                    end

filecount()

[Source]

    # File lib/ohcount/loc_list.rb, line 81
                    def filecount
                            @locs.inject(0) { |sum, loc| sum + loc.filecount }
                    end

languages()

[Source]

    # File lib/ohcount/loc_list.rb, line 14
                    def languages
                            @locs.collect { |loc| loc.language }
                    end

loc(language)

[Source]

    # File lib/ohcount/loc_list.rb, line 10
                    def loc(language)
                            @locs.find { |loc| loc.language == language.to_s }
                    end

method_missing(m, *args)

Access the individual languages directly

[Source]

    # File lib/ohcount/loc_list.rb, line 91
                    def method_missing(m, *args)
                            loc(m.to_s)
                    end

total()

[Source]

    # File lib/ohcount/loc_list.rb, line 77
                    def total
                            @locs.inject(0) { |sum, loc| sum + loc.total }
                    end

[Validate]