Class: Radiustar::Packet::Attribute

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/radiustar/packet.rb', line 235

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

#dict ⇒ Object (readonly)

Returns the value of attribute dict.



232
233
234
# File 'lib/radiustar/packet.rb', line 232

def dict
  @dict
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



232
233
234
# File 'lib/radiustar/packet.rb', line 232

def name
  @name
end

#value ⇒ Object

Returns the value of attribute value.



233
234
235
# File 'lib/radiustar/packet.rb', line 233

def value
  @value
end

#vendor ⇒ Object (readonly)

Returns the value of attribute vendor.



232
233
234
# File 'lib/radiustar/packet.rb', line 232

def vendor
  @vendor
end

Instance Method Details

#inspect ⇒ Object



267
268
269
# File 'lib/radiustar/packet.rb', line 267

def inspect
  @value
end

#pack ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/radiustar/packet.rb', line 252

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_s ⇒ Object



271
272
273
# File 'lib/radiustar/packet.rb', line 271

def to_s
  @value
end

#vendor? ⇒ Boolean



248
249
250
# File 'lib/radiustar/packet.rb', line 248

def vendor?
  !!@vendor
end