Class: OpenldapMonitorExtractor::MonitorData

Inherits:
Object
  • Object
show all
Defined in:
lib/openldap_monitor_extractor/monitor_data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mapper = Mapper) ⇒ MonitorData

Returns a new instance of MonitorData.



22
23
24
25
26
27
28
# File 'lib/openldap_monitor_extractor/monitor_data.rb', line 22

def initialize(mapper=Mapper)
  
  @data   = OpenStruct.new
  @mapper = mapper
  
  self
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/openldap_monitor_extractor/monitor_data.rb', line 10

def data
  @data
end

Class Method Details

.transform(data, type) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/openldap_monitor_extractor/monitor_data.rb', line 12

def self.transform(data, type)
  
  case type
    when :counter   then data.to_i
    when :timestamp then Time.parse(data)
  else 
    raise ArgumentError.new("Invalid data type: #{type}")
  end      
end

Instance Method Details

#add(key, entry) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/openldap_monitor_extractor/monitor_data.rb', line 30

def add(key, entry)
  
  raise ArgumentError.new("Invalid key: #{key}") unless @mapper.validate_key(key)
  
  type    = @mapper.type(key)
  value   = entry[0][@mapper.attribute(key)][0]
  t_value = MonitorData.transform(value, type)
  
  @data.send("#{key}=", t_value)
  
  self
end