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

Returns a new instance of Attribute.



212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/radiustar/packet.rb', line 212

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.



209
210
211
# File 'lib/radiustar/packet.rb', line 209

def dict
  @dict
end

#nameObject (readonly)

Returns the value of attribute name.



209
210
211
# File 'lib/radiustar/packet.rb', line 209

def name
  @name
end

#valueObject

Returns the value of attribute value.



210
211
212
# File 'lib/radiustar/packet.rb', line 210

def value
  @value
end

#vendorObject (readonly)

Returns the value of attribute vendor.



209
210
211
# File 'lib/radiustar/packet.rb', line 209

def vendor
  @vendor
end

Instance Method Details

#inspectObject



244
245
246
# File 'lib/radiustar/packet.rb', line 244

def inspect
  @value
end

#packObject



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

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



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

def to_s
  @value
end

#vendor?Boolean

Returns:

  • (Boolean)


225
226
227
# File 'lib/radiustar/packet.rb', line 225

def vendor?
  !!@vendor
end