Class: Radiustar::Dictionary

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

Constant Summary collapse

DEFAULT_DICTIONARY_PATH =
::File.join(::File.dirname(__FILE__), '..', '..', 'templates', 'default.txt')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_path = nil) ⇒ Dictionary

Returns a new instance of Dictionary.



7
8
9
10
11
# File 'lib/radiustar/dictionary.rb', line 7

def initialize(initial_path = nil)
  @attributes = AttributesCollection.new

  read initial_path if initial_path
end

Class Method Details

.defaultObject



48
49
50
# File 'lib/radiustar/dictionary.rb', line 48

def default
  new DEFAULT_DICTIONARY_PATH
end

Instance Method Details

#attribute_id_defined?(id) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/radiustar/dictionary.rb', line 40

def attribute_id_defined?(id)
  !@attributes.find_by_id(id).nil?
end

#attribute_name_defined?(name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/radiustar/dictionary.rb', line 36

def attribute_name_defined?(name)
  !@attributes.find_by_name(name).nil?
end

#find_attribute_by_id(id) ⇒ Object



32
33
34
# File 'lib/radiustar/dictionary.rb', line 32

def find_attribute_by_id(id)
  @attributes.find_by_id(id)
end

#find_attribute_by_name(name) ⇒ Object



28
29
30
# File 'lib/radiustar/dictionary.rb', line 28

def find_attribute_by_name(name)
  @attributes.find_by_name(name)
end

#read(path) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/radiustar/dictionary.rb', line 13

def read(path)
  file = File.open(path) do |f|
    f.each_line do |line|
    	next if line =~ /^\#/	# discard comments
    	split_line = line.split(/\s+/)
    	next if split_line == []
      case split_line.first.upcase
      when "ATTRIBUTE"
        set_attr(split_line)
      when "VALUE"
        set_value(split_line)
      end
    end
  end

  def find_attribute_by_name(name)
    @attributes.find_by_name(name)
  end

  def find_attribute_by_id(id)
    @attributes.find_by_id(id)
  end

  def attribute_name_defined?(name)
    !@attributes.find_by_name(name).nil?
  end

  def attribute_id_defined?(id)
    !@attributes.find_by_id(id).nil?
  end

end