Class: RadiusRB::Packet::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/radiusrb/packet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dict, name, value, vendor = nil) ⇒ Attribute

Returns a new instance of Attribute.



229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/radiusrb/packet.rb', line 229

def initialize dict, name, value, vendor=nil
  @dict = dict
  # This is the cheapest and easiest way to add VSA's!
  if (name && (chunks = name.split('/')) && (chunks.size == 2))
    @vendor = chunks[0]
    @name = chunks[1]
  else
    @name = name
  end
  @vendor ||= vendor
  @value = value.is_a?(Attribute) ? value.to_s : value
end

Instance Attribute Details

#dictObject (readonly)

Returns the value of attribute dict.



226
227
228
# File 'lib/radiusrb/packet.rb', line 226

def dict
  @dict
end

#nameObject (readonly)

Returns the value of attribute name.



226
227
228
# File 'lib/radiusrb/packet.rb', line 226

def name
  @name
end

#valueObject

Returns the value of attribute value.



227
228
229
# File 'lib/radiusrb/packet.rb', line 227

def value
  @value
end

#vendorObject (readonly)

Returns the value of attribute vendor.



226
227
228
# File 'lib/radiusrb/packet.rb', line 226

def vendor
  @vendor
end

Instance Method Details

#inspectObject



261
262
263
# File 'lib/radiusrb/packet.rb', line 261

def inspect
  @value
end

#packObject



246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/radiusrb/packet.rb', line 246

def pack
  attribute = if (vendor? && (@dict.vendors.find_by_name(@vendor)))
                @dict.vendors.find_by_name(@vendor).attributes.find_by_name(@name)
              else
                @dict.find_attribute_by_name(@name)
              end
  raise "Undefined attribute '#{@name}'." if attribute.nil?

  if vendor?
    pack_vendor_specific_attribute attribute
  else
    pack_attribute attribute
  end
end

#to_sObject



265
266
267
# File 'lib/radiusrb/packet.rb', line 265

def to_s
  @value
end

#vendor?Boolean

Returns:

  • (Boolean)


242
243
244
# File 'lib/radiusrb/packet.rb', line 242

def vendor?
  !!@vendor
end