class CLOC class CSVError < StandardError; end def initialize(cloc_csv) fail "Not a CSV: #{cloc_csv}" unless cloc_csv.is_a? CSV::Table @cloc_csv = cloc_csv end def language_counts @cloc_csv.map { |row| next if row.empty? language = row["language"] sloc = Integer(row["code"]) file_count = Integer(row["files"]) LanguageCount.new(language, sloc, file_count) }.compact end LanguageCount = Struct.new(:language, :sloc, :file_count) end