Class: Inertia::Mass

Inherits:
Object
  • Object
show all
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

GroupedMass

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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

Returns:

  • (Boolean)


42
43
44
# File 'lib/inertia/mass.rb', line 42

def erb?
  @erb ||= extension == '.erb'
end

#extensionObject



54
55
56
# File 'lib/inertia/mass.rb', line 54

def extension
  @extension ||= File.extname(path)
end

#haml?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/inertia/mass.rb', line 34

def haml?
  @haml ||= extension == '.haml'
end

#ignored?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


18
19
20
# File 'lib/inertia/mass.rb', line 18

def js?
  @js ||= extension == '.js'
end

#jsx?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/inertia/mass.rb', line 22

def jsx?
  @jsx ||= extension == '.jsx'
end

#linesObject



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_linesObject



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

Returns:

  • (Boolean)


38
39
40
# File 'lib/inertia/mass.rb', line 38

def rabl?
  @rabl ||= extension == '.rabl'
end

#ruby_spec?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/inertia/mass.rb', line 46

def ruby_spec?
  @ruby_spec ||= path.include?('_spec.rb')
end

#scss?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/inertia/mass.rb', line 14

def scss?
  @scss ||= extension == '.scss'
end

#text?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/inertia/mass.rb', line 10

def text?
  @text ||= File.open(path) { |file| file.read.ascii_only? }
end

#to_sObject



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

Returns:

  • (Boolean)


26
27
28
# File 'lib/inertia/mass.rb', line 26

def ts?
  @ts ||= extension == '.ts'
end

#tsx?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/inertia/mass.rb', line 30

def tsx?
  @tsx ||= extension == '.tsx'
end

#yml?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/inertia/mass.rb', line 50

def yml?
  @yml ||= extension == '.yml'
end