Class: Meteoroid::Sample

Inherits:
Object
  • Object
show all
Defined in:
lib/meteoroid/sample.rb

Constant Summary collapse

ATTRIBUTE_MAPPING =
{
  't'  => :time,
  'lt' => :latency,
  'ts' => :timestamp,
  's'  => :success,
  'lb' => :label,
  'rc' => :response_code,
  'rm' => :response_message,
  'tn' => :thread_name,
  'by' => :bytes,
  'u'  => :url
}
ATTRIBUTE_CONVERSION =
{
  't'  => lambda { |t|  t.to_i },
  'lt' => lambda { |lt| lt.to_i },
  'ts' => lambda { |ts| Time.at(ts.to_i / 1000) },
  's'  => lambda { |s|  s.to_s == 'true' },
  'lb' => lambda { |lb| lb.to_s },
  'rc' => lambda { |rc| rc.to_i },
  'rm' => lambda { |rm| rm.to_s },
  'tn' => lambda { |tn| tn.to_s },
  'by' => lambda { |by| by.to_i },
  'u'  => lambda { |u|  u.to_s }
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Sample

Returns a new instance of Sample.



32
33
34
35
36
# File 'lib/meteoroid/sample.rb', line 32

def initialize attributes
  ATTRIBUTE_MAPPING.each do |key, value|
    instance_variable_set(:"@#{value}", convert(key, attributes[key]))
  end
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.from_xml(attribute_nodes, url = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/meteoroid/sample.rb', line 38

def self.from_xml attribute_nodes, url = nil
  attributes = {}

  attribute_nodes.each do |node|
    attributes[node.name] = node.value
  end

  attributes.merge!({'u' => url}) if url

  new(attributes)
end