Module: Unitwise::Search

Defined in:
lib/unitwise/search.rb

Class Method Summary collapse

Class Method Details

.allArray

An abbreviated list of possible units. These are known combinations of atoms and prefixes. Since units can be combined to create more complex units (and thus an infinite number), a full list can’t be provided.

Returns:

  • (Array)

    A list of known units



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

def all
  @all ||= begin
    units = []
    Atom.all.each do |a|
      units << build(a)
      Unitwise::Prefix.all.each { |p| units << build(a,p) } if a.metric?
    end
    units
  end
end

.search(term) ⇒ Array

Search the list of known units for a match. Note that this cannot find all possible units, only simple combinations of atoms and prefixes.

Parameters:

  • term (String, Regexp)

    The term to search for

Returns:

  • (Array)

    A list of matching units.



26
27
28
29
30
# File 'lib/unitwise/search.rb', line 26

def search(term)
  all.select do |unit|
    unit.aliases.any? { |str| Regexp.new(term).match(str) }
  end
end