Class: MetzScan::Analyzers::Occurrence

Inherits:
Struct
  • Object
show all
Defined in:
lib/metz_scan/analyzers/occurrence.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



7
8
9
# File 'lib/metz_scan/analyzers/occurrence.rb', line 7

def context
  @context
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



7
8
9
# File 'lib/metz_scan/analyzers/occurrence.rb', line 7

def line
  @line
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



7
8
9
# File 'lib/metz_scan/analyzers/occurrence.rb', line 7

def path
  @path
end

Class Method Details

.from(value, context: nil) ⇒ Object



8
9
10
11
12
13
# File 'lib/metz_scan/analyzers/occurrence.rb', line 8

def self.from(value, context: nil)
  return value if value.is_a?(self)
  return nil unless value.respond_to?(:path) && value.path

  new(path: value.path, line: line_for(value), context: context)
end

.line_for(value) ⇒ Object



15
16
17
# File 'lib/metz_scan/analyzers/occurrence.rb', line 15

def self.line_for(value)
  value.line if value.respond_to?(:line)
end

Instance Method Details

#line_sourceObject



23
24
25
# File 'lib/metz_scan/analyzers/occurrence.rb', line 23

def line_source
  line ? "source" : "fallback"
end

#report_lineObject



19
20
21
# File 'lib/metz_scan/analyzers/occurrence.rb', line 19

def report_line
  line || MetzScan::Analyzers::FALLBACK_LINE
end