Class: Plextail::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/plextail/line.rb

Constant Summary collapse

DEFAULTS =
{
  :version    => '<134>1',
  :hostname   => `hostname`.strip,
  :message_id => '- -'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, raw) ⇒ Line

Returns a new instance of Line.



11
12
13
14
15
16
17
18
# File 'lib/plextail/line.rb', line 11

def initialize(file, raw)
  @file, @raw = file, raw
  @version    = DEFAULTS[:version]
  @timestamp  = current_timestamp
  @hostname   = DEFAULTS[:hostname]
  @message_id = DEFAULTS[:message_id]
  @message    = raw.dup
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



8
9
10
# File 'lib/plextail/line.rb', line 8

def file
  @file
end

#hostnameObject

Returns the value of attribute hostname.



8
9
10
# File 'lib/plextail/line.rb', line 8

def hostname
  @hostname
end

#messageObject

Returns the value of attribute message.



8
9
10
# File 'lib/plextail/line.rb', line 8

def message
  @message
end

#message_idObject

Returns the value of attribute message_id.



8
9
10
# File 'lib/plextail/line.rb', line 8

def message_id
  @message_id
end

#process_idObject

Returns the value of attribute process_id.



8
9
10
# File 'lib/plextail/line.rb', line 8

def process_id
  @process_id
end

#rawObject

Returns the value of attribute raw.



8
9
10
# File 'lib/plextail/line.rb', line 8

def raw
  @raw
end

#timestampObject

Returns the value of attribute timestamp.



8
9
10
# File 'lib/plextail/line.rb', line 8

def timestamp
  @timestamp
end

#tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/plextail/line.rb', line 8

def token
  @token
end

#versionObject

Returns the value of attribute version.



8
9
10
# File 'lib/plextail/line.rb', line 8

def version
  @version
end

Instance Method Details

#to_sObject



20
21
22
23
24
25
26
27
28
# File 'lib/plextail/line.rb', line 20

def to_s
  unless valid?
    raise Plextail::InvalidLineError, "Missing #{missing_parts.join(', ')}"
  end

  string = parts.join(' ')

  "#{string.bytes.to_a.length} #{string}"
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  parts.all? { |part| part && part.length > 0 }
end