Class: Acronym

Inherits:
Object
  • Object
show all
Defined in:
lib/wcdma_bb/acronym.rb

Overview

Collect, hold, and look up all acronyms

Author:

  • Michael Duo Ling

Constant Summary collapse

@@acronyms =

a hash containing all acronyms: string => array of strings

Hash.new

Class Method Summary collapse

Class Method Details

.add(acronym, fullname) ⇒ nil

Store acronym => fullname pair

Parameters:

  • acronym (String)

    the abbreviation

  • fullname (String)

    the full name

Returns:

  • (nil)

    nothing



13
14
15
16
17
18
19
# File 'lib/wcdma_bb/acronym.rb', line 13

def self.add(acronym, fullname)
    values = @@acronyms.fetch(acronym, Array.new)
    if not values.include?(fullname)
        values << fullname
        @@acronyms[acronym] = values
    end
end

.clearnil

Clear all saved acronyms

Returns:

  • (nil)

    nothing



37
38
39
# File 'lib/wcdma_bb/acronym.rb', line 37

def self.clear()
    @@acronyms = Hash.new
end

.search_acronym(pattern) ⇒ Hash

Look up for one acronym pattern

Parameters:

  • pattern (String)

    acronym pattern (regex)

Returns:

  • (Hash)

    acronym => array of fullnames for all acronyms that match given pattern



24
25
26
27
28
29
30
31
32
33
# File 'lib/wcdma_bb/acronym.rb', line 24

def self.search_acronym(pattern)
    result = Hash.new
    pattern = Regexp.new(pattern)
    @@acronyms.each { |key, value|
        if pattern.match(key)
            result[key] = value
        end
    }
    return result
end