Class: Inertia::Mass
- Inherits:
-
Object
- Object
- Inertia::Mass
- Defined in:
- lib/inertia/mass.rb
Overview
Mass is a location where code lives. This represents a single location and encapsulates data relating to it.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #erb? ⇒ Boolean
- #extension ⇒ Object
- #haml? ⇒ Boolean
- #ignored? ⇒ Boolean
-
#initialize(path:) ⇒ Mass
constructor
A new instance of Mass.
- #js? ⇒ Boolean
- #jsx? ⇒ Boolean
- #lines ⇒ Object
- #percent_overall_lines ⇒ Object
- #rabl? ⇒ Boolean
- #ruby_spec? ⇒ Boolean
- #scss? ⇒ Boolean
- #text? ⇒ Boolean
- #to_s ⇒ Object
- #ts? ⇒ Boolean
- #tsx? ⇒ Boolean
- #yml? ⇒ Boolean
Constructor Details
#initialize(path:) ⇒ Mass
Returns a new instance of Mass.
5 6 7 |
# File 'lib/inertia/mass.rb', line 5 def initialize(path:) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/inertia/mass.rb', line 8 def path @path end |
Instance Method Details
#<=>(other) ⇒ Object
68 69 70 |
# File 'lib/inertia/mass.rb', line 68 def <=>(other) lines <=> other.lines end |
#erb? ⇒ Boolean
42 43 44 |
# File 'lib/inertia/mass.rb', line 42 def erb? @erb ||= extension == '.erb' end |
#extension ⇒ Object
54 55 56 |
# File 'lib/inertia/mass.rb', line 54 def extension @extension ||= File.extname(path) end |
#haml? ⇒ Boolean
34 35 36 |
# File 'lib/inertia/mass.rb', line 34 def haml? @haml ||= extension == '.haml' end |
#ignored? ⇒ Boolean
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/inertia/mass.rb', line 76 def ignored? !text? || scss? && Inertia.config.ignore_scss || js? && Inertia.config.ignore_js || jsx? && Inertia.config.ignore_jsx || ts? && Inertia.config.ignore_ts || tsx? && Inertia.config.ignore_tsx || haml? && Inertia.config.ignore_haml || rabl? && Inertia.config.ignore_rabl || erb? && Inertia.config.ignore_erb || ruby_spec? && Inertia.config.ignore_ruby_spec || yml? && Inertia.config.ignore_yml end |
#js? ⇒ Boolean
18 19 20 |
# File 'lib/inertia/mass.rb', line 18 def js? @js ||= extension == '.js' end |
#jsx? ⇒ Boolean
22 23 24 |
# File 'lib/inertia/mass.rb', line 22 def jsx? @jsx ||= extension == '.jsx' end |
#lines ⇒ Object
58 59 60 61 62 |
# File 'lib/inertia/mass.rb', line 58 def lines return 0 if ignored? @lines ||= File.open(path) { |file| file.each_line.count } end |
#percent_overall_lines ⇒ Object
64 65 66 |
# File 'lib/inertia/mass.rb', line 64 def percent_overall_lines (lines / Inertia::Resistance.total_lines.to_f * 100).round(2) end |
#rabl? ⇒ Boolean
38 39 40 |
# File 'lib/inertia/mass.rb', line 38 def rabl? @rabl ||= extension == '.rabl' end |
#ruby_spec? ⇒ Boolean
46 47 48 |
# File 'lib/inertia/mass.rb', line 46 def ruby_spec? @ruby_spec ||= path.include?('_spec.rb') end |
#scss? ⇒ Boolean
14 15 16 |
# File 'lib/inertia/mass.rb', line 14 def scss? @scss ||= extension == '.scss' end |
#text? ⇒ Boolean
10 11 12 |
# File 'lib/inertia/mass.rb', line 10 def text? @text ||= File.open(path) { |file| file.read.ascii_only? } end |
#to_s ⇒ Object
72 73 74 |
# File 'lib/inertia/mass.rb', line 72 def to_s sprintf("%6.2f%%\t%s", percent_overall_lines, path) end |
#ts? ⇒ Boolean
26 27 28 |
# File 'lib/inertia/mass.rb', line 26 def ts? @ts ||= extension == '.ts' end |
#tsx? ⇒ Boolean
30 31 32 |
# File 'lib/inertia/mass.rb', line 30 def tsx? @tsx ||= extension == '.tsx' end |
#yml? ⇒ Boolean
50 51 52 |
# File 'lib/inertia/mass.rb', line 50 def yml? @yml ||= extension == '.yml' end |