Class | Ohcount::GestaltFacts
In: | lib/ohcount/gestalt_facts.rb
Parent: | Object

Represents language statistics for a collection of files

### Methods

includes_language? language_percents new post_process process

### Attributes

file_rules | [RW] |
language_counts | [RW] |
platforms | [RW] |
tools | [RW] |

### Public Class methods

new()

[Source]

    # File lib/ohcount/gestalt_facts.rb, line 7
                    def initialize
                            @platforms = []
                            @tools = []
                            @file_rules = {}
                            @language_counts = {}
                    end

### Public Instance methods

includes_language?(language, min_percent = 0)

[Source]

    # File lib/ohcount/gestalt_facts.rb, line 50
                    def includes_language?(language, min_percent = 0)
                            return false unless language_counts[language]
                            language_percents[language] >= min_percent
                    end

language_percents()

[Source]

    # File lib/ohcount/gestalt_facts.rb, line 55
                    def language_percents
                            @language_percents ||= begin
                                    total = language_counts.values.inject(0) { |s,c| s+c }
                                    l = {}
                                    language_counts.each do |k,v|
                                            l[k] = 100.0 * v.to_i / total
                                    end
                                    l
                            end
                    end

post_process()

[Source]

    # File lib/ohcount/gestalt_facts.rb, line 25
                    def post_process
                            # since platforms can depend on other platforms,
                            # we perform an iterative process and break when
                            # no new platforms have been detected.
                            while true do
                                    prev_platforms = self.platforms.clone
                                    uninfered_platforms.each do |p|
                                            platforms << p if p.triggered?(self)
                                    end
                                    prev_tools = self.tools.clone
                                    uninfered_tools.each do |t|
                                            tools << t if t.triggered?(self)
                                    end
                                    break if prev_platforms == self.platforms && prev_tools == self.tools
                            end
                    end

process(source_file)

[Source]

    # File lib/ohcount/gestalt_facts.rb, line 14
                    def process(source_file)
                            Gestalt::FileRule.rules_triggered_by(source_file).each do |r|
                                    @file_rules[r] ||= 0
                                    @file_rules[r] += 1
                            end
                            source_file.language_breakdowns.each do |lb|
                                    @language_counts[lb.name.intern] ||= 0
                                    @language_counts[lb.name.intern] += lb.code_count
                            end
                    end

[Validate]