Class: Unitwise::Base
- Inherits:
-
Object
- Object
- Unitwise::Base
- Defined in:
- lib/unitwise/base.rb
Overview
The base class that Atom and Prefix are extended from. This class includes shared functionality from those classes only.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
- #names=(names) ⇒ Object
- #slugs ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Base
Returns a new instance of Base.
23 24 25 26 |
# File 'lib/unitwise/base.rb', line 23 def initialize(*args) super(*args) freeze end |
Class Method Details
.all ⇒ Object
8 9 10 |
# File 'lib/unitwise/base.rb', line 8 def self.all @all ||= data.map { |d| new d } end |
.find(string, method = :primary_code) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/unitwise/base.rb', line 12 def self.find(string, method = :primary_code) 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
28 29 30 |
# File 'lib/unitwise/base.rb', line 28 def names=(names) @names = Array(names) end |
#slugs ⇒ Object
32 33 34 35 36 |
# File 'lib/unitwise/base.rb', line 32 def slugs names.map do |n| n.downcase.strip.gsub(/\s/, '_').gsub(/\W/, '') end end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/unitwise/base.rb', line 38 def to_s primary_code end |