Class: Logue::LocationFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/logue/format/location_format.rb

Defined Under Namespace

Modules: Defaults

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file: Defaults::FILENAME, line: Defaults::LINE, method: Defaults::METHOD) ⇒ LocationFormat

Returns a new instance of LocationFormat.



15
16
17
18
19
# File 'lib/logue/format/location_format.rb', line 15

def initialize file: Defaults::FILENAME, line: Defaults::LINE, method: Defaults::METHOD
  @file = file
  @line = line
  @method = method
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



11
12
13
# File 'lib/logue/format/location_format.rb', line 11

def file
  @file
end

#lineObject

Returns the value of attribute line.



12
13
14
# File 'lib/logue/format/location_format.rb', line 12

def line
  @line
end

#methodObject

Returns the value of attribute method.



13
14
15
# File 'lib/logue/format/location_format.rb', line 13

def method
  @method
end

Instance Method Details

#format(path, line, cls, methname) ⇒ Object



21
22
23
24
25
26
# File 'lib/logue/format/location_format.rb', line 21

def format path, line, cls, methname
  name = cls ? cls.to_s + "#" + methname : methname
  path = PathUtil.trim_right path.to_s, @file.abs
  name = PathUtil.trim_left  name,      @method.abs
  sprintf format_string, path, line, name
end

#format_location(location) ⇒ Object



28
29
30
# File 'lib/logue/format/location_format.rb', line 28

def format_location location
  format location.path, location.line, location.cls, location.method
end

#format_stringObject



32
33
34
# File 'lib/logue/format/location_format.rb', line 32

def format_string
  "[%#{@file}s:%#{@line}d] {%#{@method}s}"
end

#to_sObject



36
37
38
# File 'lib/logue/format/location_format.rb', line 36

def to_s
  inspect
end