Class: Unitwise::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/unitwise/base.rb

Direct Known Subclasses

Atom, Prefix

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



21
22
23
24
# File 'lib/unitwise/base.rb', line 21

def initialize(*args)
  super(*args)
  freeze
end

Class Method Details

.all ⇒ Object



6
7
8
# File 'lib/unitwise/base.rb', line 6

def self.all
  @all ||= data.map{|d| self.new d }
end

.find(string, method = :primary_code) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/unitwise/base.rb', line 10

def self.find(string, method=:primary_code)
  self.all.find do |i|
    key = i.send(method)
    if key.respond_to?(:each)
      key.include?(string)
    else
      key == string
    end
  end
end

Instance Method Details

#names=(names) ⇒ Object



26
27
28
# File 'lib/unitwise/base.rb', line 26

def names=(names)
  @names = Array(names)
end

#slugs ⇒ Object



30
31
32
33
34
# File 'lib/unitwise/base.rb', line 30

def slugs
  names.map do |n|
    n.downcase.strip.gsub(/\s/, '_').gsub(/\W/, '')
  end
end

#to_s ⇒ Object



36
37
38
# File 'lib/unitwise/base.rb', line 36

def to_s
  primary_code
end