swoop_report 0.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/Guardfile +14 -0
- data/lib/swoop.rb +4 -3
- data/lib/swoop/file_info.rb +50 -0
- data/lib/swoop/{entity_parser.rb → file_parser.rb} +31 -14
- data/lib/swoop/renderer/csv_renderer.rb +2 -2
- data/lib/swoop/renderer/table_renderer.rb +27 -2
- data/lib/swoop/report.rb +61 -21
- data/lib/swoop/version.rb +1 -1
- data/screenshots/table.png +0 -0
- data/swoop.gemspec +1 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0922a69f3164be892c109b44061f09ac31f06c8
|
4
|
+
data.tar.gz: bebe25bb3b4ec903c1aee78797f6cf8f3a119337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8559e7239f34d6ec739ae95b49c130d8587faa5680303fa03c782064a2bbbd62f99e201bce7395c491048eb57cfb7a9634d921d13b8aafd2ee6e4b5bd5ce8460
|
7
|
+
data.tar.gz: 225f1f3ac280592afe588670c2fb2f0f585f6383ff25254ba3e4179963e1e9cdb89f31f90f050c2e38fcfa8f1d2c177ffba13e6da54441d28d98b59dab00dd78
|
data/CHANGELOG.md
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
2
|
+
require "guard/rspec/dsl"
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
# RSpec files
|
6
|
+
rspec = dsl.rspec
|
7
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
8
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
9
|
+
watch(rspec.spec_files)
|
10
|
+
|
11
|
+
# Ruby files
|
12
|
+
ruby = dsl.ruby
|
13
|
+
watch(ruby.lib_files) { rspec.spec_dir }
|
14
|
+
end
|
data/lib/swoop.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require "swoop/version"
|
2
2
|
require "swoop/project"
|
3
3
|
require "swoop/entity"
|
4
|
-
require "swoop/
|
4
|
+
require "swoop/file_parser"
|
5
|
+
require "swoop/file_info"
|
5
6
|
require "swoop/report"
|
6
7
|
require "swoop/time_machine"
|
7
8
|
|
@@ -57,8 +58,8 @@ module Swoop
|
|
57
58
|
project = Project.new(@project_path, @dir_path)
|
58
59
|
delorean = TimeMachine.new(project, time_machine_options)
|
59
60
|
delorean.travel do |proj, name, date|
|
60
|
-
|
61
|
-
reports << Report.new(
|
61
|
+
file_infos = FileParser.parse(proj.filepaths)
|
62
|
+
reports << Report.new(file_infos, name, date)
|
62
63
|
end
|
63
64
|
|
64
65
|
reports
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Swoop
|
2
|
+
|
3
|
+
module Lang
|
4
|
+
NONE = 0
|
5
|
+
OBJC = 1
|
6
|
+
SWIFT = 2
|
7
|
+
end
|
8
|
+
|
9
|
+
class FileInfo
|
10
|
+
|
11
|
+
attr_reader :filepath, :language, :line_count, :classes, :structs, :extensions
|
12
|
+
|
13
|
+
def initialize(filepath, language, line_count, classes, structs, extensions)
|
14
|
+
@filepath = filepath
|
15
|
+
@language = language
|
16
|
+
@line_count = line_count
|
17
|
+
@classes = classes
|
18
|
+
@structs = structs
|
19
|
+
@extensions = extensions
|
20
|
+
end
|
21
|
+
|
22
|
+
def swift?
|
23
|
+
language == Lang::SWIFT
|
24
|
+
end
|
25
|
+
|
26
|
+
def objc?
|
27
|
+
language == Lang::OBJC
|
28
|
+
end
|
29
|
+
|
30
|
+
def entities
|
31
|
+
@entities ||= begin
|
32
|
+
[ *classes, *structs, *extensions ]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def hash
|
37
|
+
filepath.hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def eql?(comparee)
|
41
|
+
self == comparee
|
42
|
+
end
|
43
|
+
|
44
|
+
def ==(comparee)
|
45
|
+
self.filepath == comparee.filepath
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -2,31 +2,44 @@ require 'json'
|
|
2
2
|
|
3
3
|
module Swoop
|
4
4
|
|
5
|
-
class
|
5
|
+
class FileParser
|
6
6
|
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :entityInfos
|
8
8
|
|
9
|
-
def self.
|
10
|
-
filepaths
|
11
|
-
.map { |p| self.new(p).entities }
|
12
|
-
.flatten
|
13
|
-
.uniq
|
9
|
+
def self.parse(filepaths)
|
10
|
+
filepaths.map { |p| self.new(p).entityInfos }.compact.uniq
|
14
11
|
end
|
15
12
|
|
16
13
|
def initialize(filepath)
|
17
14
|
@filepath = filepath
|
18
15
|
end
|
19
16
|
|
20
|
-
def
|
21
|
-
@
|
22
|
-
return parse_swift if
|
23
|
-
return parse_objc if
|
24
|
-
|
17
|
+
def entityInfos
|
18
|
+
@entityInfos ||= begin
|
19
|
+
return parse_swift if swift_file?
|
20
|
+
return parse_objc if objc_header_file? || objc_implementation_file?
|
21
|
+
nil
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
25
|
private
|
29
26
|
|
27
|
+
def swift_file?
|
28
|
+
File.extname(@filepath) == ".swift"
|
29
|
+
end
|
30
|
+
|
31
|
+
def objc_header_file?
|
32
|
+
File.extname(@filepath) == ".h"
|
33
|
+
end
|
34
|
+
|
35
|
+
def objc_implementation_file?
|
36
|
+
File.extname(@filepath) == ".m"
|
37
|
+
end
|
38
|
+
|
39
|
+
def lines_count
|
40
|
+
File.new(@filepath).readlines.size
|
41
|
+
end
|
42
|
+
|
30
43
|
LANG_SWIFT = 'swift'
|
31
44
|
LANG_OBJC = 'objc'
|
32
45
|
TYPE_CLASS = 'class'
|
@@ -42,7 +55,7 @@ module Swoop
|
|
42
55
|
structs = filter(SWIFT_STRUCT).map { |e| Entity.new(e, LANG_SWIFT, TYPE_STRUCT) }
|
43
56
|
extensions = filter(SWIFT_EXT).map { |e| Entity.new(e, LANG_SWIFT, TYPE_EXTENSION) }
|
44
57
|
|
45
|
-
|
58
|
+
FileInfo.new(@filepath, Lang::SWIFT, lines_count, classes, structs, extensions)
|
46
59
|
end
|
47
60
|
|
48
61
|
OBJC_CLASS = '@interface\s*(\w+)\s*:'
|
@@ -50,6 +63,9 @@ module Swoop
|
|
50
63
|
OBJC_STRUCT ='typedef\s*struct\s*{.*?}\s*(\w*)'
|
51
64
|
OBJC_STRUCT2 = 'struct\s*(\w+)'
|
52
65
|
def parse_objc
|
66
|
+
# Only counting the lines and the file
|
67
|
+
return FileInfo.new(@filepath, Lang::OBJC, lines_count, [], [], []) if objc_implementation_file?
|
68
|
+
|
53
69
|
classes = filter(OBJC_CLASS).map { |e| Entity.new(e, LANG_OBJC, TYPE_CLASS) }
|
54
70
|
categories = filter(OBJC_CATEGORY, false)
|
55
71
|
.map { |exts|
|
@@ -59,7 +75,7 @@ module Swoop
|
|
59
75
|
structs = (filter(OBJC_STRUCT, true, Regexp::MULTILINE) + filter(OBJC_STRUCT2))
|
60
76
|
.map { |e| Entity.new(e, LANG_OBJC, TYPE_STRUCT) }
|
61
77
|
|
62
|
-
|
78
|
+
FileInfo.new(@filepath, Lang::OBJC, lines_count, classes, structs, categories)
|
63
79
|
end
|
64
80
|
|
65
81
|
def file_content
|
@@ -77,6 +93,7 @@ module Swoop
|
|
77
93
|
return filtered unless should_flatten
|
78
94
|
filtered.flatten
|
79
95
|
end
|
96
|
+
|
80
97
|
end
|
81
98
|
|
82
99
|
end
|
@@ -22,10 +22,10 @@ module Swoop
|
|
22
22
|
def csv
|
23
23
|
@csv ||= begin
|
24
24
|
lines = []
|
25
|
-
lines << "name,date,swift class,swift class %,objc class,objc class %,total class,swift struct,swift struct %,objc struct,objc struct %,total struct,swift extension,swift extension %,objc extension,objc extension %,total extension"
|
25
|
+
lines << "name,date,swift lines,swift lines %,objc lines,objc lines %,total lines,swift files,swift files %,objc files,objc files %,total files,swift class,swift class %,objc class,objc class %,total class,swift struct,swift struct %,objc struct,objc struct %,total struct,swift extension,swift extension %,objc extension,objc extension %,total extension"
|
26
26
|
|
27
27
|
reports.each do |report|
|
28
|
-
lines << "#{report.name},#{report.date},#{report.swift_classes_count},#{'%.02f' % report.swift_classes_percentage},#{report.objc_classes_count},#{'%.02f' % report.objc_classes_percentage},#{report.classes_count},#{report.swift_structs_count},#{'%.02f' % report.swift_structs_percentage},#{report.objc_structs_count},#{'%.02f' % report.objc_structs_percentage},#{report.structs_count},#{report.swift_extensions_count},#{'%.02f' % report.swift_extensions_percentage},#{report.objc_extensions_count},#{'%.02f' % report.objc_extensions_percentage},#{report.extensions_count}"
|
28
|
+
lines << "#{report.name},#{report.date},#{report.swift_lines_count},#{'%.02f' % report.swift_lines_percentage},#{report.objc_lines_count},#{'%.02f' % report.objc_lines_percentage},#{report.lines_count},#{report.swift_files_count},#{'%.02f' % report.swift_files_percentage},#{report.objc_files_count},#{'%.02f' % report.objc_files_percentage},#{report.files_count},#{report.swift_classes_count},#{'%.02f' % report.swift_classes_percentage},#{report.objc_classes_count},#{'%.02f' % report.objc_classes_percentage},#{report.classes_count},#{report.swift_structs_count},#{'%.02f' % report.swift_structs_percentage},#{report.objc_structs_count},#{'%.02f' % report.objc_structs_percentage},#{report.structs_count},#{report.swift_extensions_count},#{'%.02f' % report.swift_extensions_percentage},#{report.objc_extensions_count},#{'%.02f' % report.objc_extensions_percentage},#{report.extensions_count}"
|
29
29
|
end
|
30
30
|
|
31
31
|
lines.join("\n")
|
@@ -10,10 +10,35 @@ module Swoop
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
+
def f(lines)
|
14
|
+
return lines if lines < 1_000
|
15
|
+
|
16
|
+
count_in_thousand = Integer(Float(lines) / Float(1_000))
|
17
|
+
"#{count_in_thousand}K"
|
18
|
+
end
|
19
|
+
|
13
20
|
def table
|
14
|
-
headings = [
|
21
|
+
headings = [
|
22
|
+
"name", "date",
|
23
|
+
"swift\nfiles (%)", "objc\nfiles (%)",
|
24
|
+
"swift\nlines (%)", "objc\nlines (%)",
|
25
|
+
"swift\nclass (%)", "objc\nclass (%)",
|
26
|
+
"swift\nstruct(%)", "objc\nstruct(%)",
|
27
|
+
"swift\next(%)", "objc\next(%)"
|
28
|
+
]
|
15
29
|
rows = reports.map do |r|
|
16
|
-
[r.name,r.date,
|
30
|
+
[r.name,r.date,
|
31
|
+
"#{'%.02f' % r.swift_files_percentage} (#{f r.swift_files_count}/#{f r.files_count})",
|
32
|
+
"#{'%.02f' % r.objc_files_percentage} (#{f r.objc_files_count}/#{f r.files_count})",
|
33
|
+
"#{'%.02f' % r.swift_lines_percentage} (#{f r.swift_lines_count}/#{f r.lines_count})",
|
34
|
+
"#{'%.02f' % r.objc_lines_percentage} (#{f r.objc_lines_count}/#{f r.lines_count})",
|
35
|
+
"#{'%.02f' % r.swift_classes_percentage} (#{r.swift_classes_count}/#{r.classes_count})",
|
36
|
+
"#{'%.02f' % r.objc_classes_percentage} (#{r.objc_classes_count}/#{r.classes_count})",
|
37
|
+
"#{'%.02f' % r.swift_structs_percentage} (#{r.swift_structs_count}/#{r.structs_count})",
|
38
|
+
"#{'%.02f' % r.objc_structs_percentage} (#{r.objc_structs_count}/#{r.structs_count})",
|
39
|
+
"#{'%.02f' % r.swift_extensions_percentage} (#{r.swift_extensions_count}/#{r.extensions_count})",
|
40
|
+
"#{'%.02f' % r.objc_extensions_percentage} (#{r.objc_extensions_count}/#{r.extensions_count})",
|
41
|
+
]
|
17
42
|
end
|
18
43
|
|
19
44
|
@table ||= Terminal::Table.new(:title => title, :headings => headings, :rows => rows)
|
data/lib/swoop/report.rb
CHANGED
@@ -4,8 +4,8 @@ module Swoop
|
|
4
4
|
|
5
5
|
attr_reader :name
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(file_infos, name = '', date = Time.now)
|
8
|
+
@file_infos = file_infos
|
9
9
|
@date = date
|
10
10
|
|
11
11
|
if name.nil? || name == ''
|
@@ -19,6 +19,52 @@ module Swoop
|
|
19
19
|
@date.strftime("%d-%m-%Y")
|
20
20
|
end
|
21
21
|
|
22
|
+
# Files
|
23
|
+
def files_count
|
24
|
+
@files_count ||= @file_infos.count
|
25
|
+
end
|
26
|
+
|
27
|
+
def swift_files_count
|
28
|
+
@swift_files_count ||= swift_file_infos.count
|
29
|
+
end
|
30
|
+
|
31
|
+
def objc_files_count
|
32
|
+
@objc_files_count ||= objc_file_infos.count
|
33
|
+
end
|
34
|
+
|
35
|
+
def swift_files_percentage
|
36
|
+
return 0 if files_count == 0
|
37
|
+
(swift_files_count.to_f / files_count) * 100
|
38
|
+
end
|
39
|
+
|
40
|
+
def objc_files_percentage
|
41
|
+
return 0 if files_count == 0
|
42
|
+
(objc_files_count.to_f / files_count) * 100
|
43
|
+
end
|
44
|
+
|
45
|
+
# Lines
|
46
|
+
def lines_count
|
47
|
+
@lines_count ||= @file_infos.map(&:line_count).reduce(:+)
|
48
|
+
end
|
49
|
+
|
50
|
+
def swift_lines_count
|
51
|
+
@swift_lines_count ||= swift_file_infos.map(&:line_count).reduce(:+)
|
52
|
+
end
|
53
|
+
|
54
|
+
def objc_lines_count
|
55
|
+
@objc_lines_count ||= objc_file_infos.map(&:line_count).reduce(:+)
|
56
|
+
end
|
57
|
+
|
58
|
+
def swift_lines_percentage
|
59
|
+
return 0 if lines_count == 0
|
60
|
+
(swift_lines_count.to_f / lines_count) * 100
|
61
|
+
end
|
62
|
+
|
63
|
+
def objc_lines_percentage
|
64
|
+
return 0 if lines_count == 0
|
65
|
+
(objc_lines_count.to_f / lines_count) * 100
|
66
|
+
end
|
67
|
+
|
22
68
|
# Classes
|
23
69
|
def classes_count
|
24
70
|
classes.count
|
@@ -90,56 +136,50 @@ module Swoop
|
|
90
136
|
(objc_extensions_count.to_f / extensions_count) * 100
|
91
137
|
end
|
92
138
|
|
93
|
-
def to_s
|
94
|
-
"Class | swift : #{swift_classes_count} (#{'%.02f' % swift_classes_percentage}%) , objc : #{objc_classes_count} (#{'%.02f' % objc_classes_percentage}%), total: #{classes_count} \n" +
|
95
|
-
"Structs | swift : #{swift_structs_count} (#{'%.02f' % swift_structs_percentage}%) , objc : #{objc_structs_count} (#{'%.02f' % objc_structs_percentage}%), total: #{structs_count} \n" +
|
96
|
-
"Extensions | swift : #{swift_extensions_count} (#{'%.02f' % swift_extensions_percentage}%) , objc : #{objc_extensions_count} (#{'%.02f' % objc_extensions_percentage}%), total: #{extensions_count}"
|
97
|
-
end
|
98
|
-
|
99
139
|
private
|
100
140
|
|
101
141
|
def classes
|
102
|
-
@classes ||= @
|
142
|
+
@classes ||= @file_infos.flat_map(&:classes)
|
103
143
|
end
|
104
144
|
|
105
145
|
def structs
|
106
|
-
@structs ||= @
|
146
|
+
@structs ||= @file_infos.flat_map(&:structs)
|
107
147
|
end
|
108
148
|
|
109
149
|
def extensions
|
110
|
-
@extensions ||= @
|
150
|
+
@extensions ||= @file_infos.flat_map(&:extensions).uniq
|
111
151
|
end
|
112
152
|
|
113
|
-
def
|
114
|
-
@
|
153
|
+
def swift_file_infos
|
154
|
+
@swift_file_infos ||= @file_infos.select(&:swift?)
|
115
155
|
end
|
116
156
|
|
117
157
|
def swift_classes
|
118
|
-
@swift_classes ||=
|
158
|
+
@swift_classes ||= swift_file_infos.flat_map(&:classes)
|
119
159
|
end
|
120
160
|
|
121
161
|
def swift_structs
|
122
|
-
@swift_structs ||=
|
162
|
+
@swift_structs ||= swift_file_infos.flat_map(&:structs)
|
123
163
|
end
|
124
164
|
|
125
165
|
def swift_extensions
|
126
|
-
@swift_extensions ||=
|
166
|
+
@swift_extensions ||= swift_file_infos.flat_map(&:extensions).uniq
|
127
167
|
end
|
128
168
|
|
129
|
-
def
|
130
|
-
@
|
169
|
+
def objc_file_infos
|
170
|
+
@objc_file_infos ||= @file_infos.select(&:objc?)
|
131
171
|
end
|
132
172
|
|
133
173
|
def objc_classes
|
134
|
-
@objc_classes ||=
|
174
|
+
@objc_classes ||= objc_file_infos.flat_map(&:classes)
|
135
175
|
end
|
136
176
|
|
137
177
|
def objc_structs
|
138
|
-
@objc_structs ||=
|
178
|
+
@objc_structs ||= objc_file_infos.flat_map(&:structs)
|
139
179
|
end
|
140
180
|
|
141
181
|
def objc_extensions
|
142
|
-
@objc_extensions ||=
|
182
|
+
@objc_extensions ||= objc_file_infos.flat_map(&:extensions).uniq
|
143
183
|
end
|
144
184
|
end
|
145
185
|
end
|
data/lib/swoop/version.rb
CHANGED
data/screenshots/table.png
CHANGED
Binary file
|
data/swoop.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rspec", "~> 3.0"
|
23
23
|
spec.add_development_dependency "pry", "~> 0.10.3"
|
24
24
|
spec.add_development_dependency "coveralls"
|
25
|
+
spec.add_development_dependency "guard-rspec"
|
25
26
|
|
26
27
|
spec.add_runtime_dependency "thor", "~> 0.19"
|
27
28
|
spec.add_runtime_dependency "xcodeproj", "~> 1.2"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swoop_report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ikhsan Assaat
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: thor
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,6 +164,7 @@ files:
|
|
150
164
|
- ".travis.yml"
|
151
165
|
- CHANGELOG.md
|
152
166
|
- Gemfile
|
167
|
+
- Guardfile
|
153
168
|
- LICENSE.txt
|
154
169
|
- README.md
|
155
170
|
- Rakefile
|
@@ -158,7 +173,8 @@ files:
|
|
158
173
|
- exe/swoop
|
159
174
|
- lib/swoop.rb
|
160
175
|
- lib/swoop/entity.rb
|
161
|
-
- lib/swoop/
|
176
|
+
- lib/swoop/file_info.rb
|
177
|
+
- lib/swoop/file_parser.rb
|
162
178
|
- lib/swoop/project.rb
|
163
179
|
- lib/swoop/renderer/chart_renderer.rb
|
164
180
|
- lib/swoop/renderer/chart_renderer/chart.html.erb
|