Module: Unitwise::Search
- Defined in:
- lib/unitwise/search.rb
Class Method Summary collapse
-
.all ⇒ Array
An abbreviated list of possible units.
-
.search(term) ⇒ Array
Search the list of known units for a match.
Class Method Details
.all ⇒ Array
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.
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.
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 |