module Unitwise::Search

The search module provides a simple search mechanism around known basic units. The full list of avaliable units infinite, so this search creates a small subset of atoms and prefixes to help users find what they are looking for. Thus, there is a multitude of valid units that may be constructed that this module will not be aware of.

Public Class Methods

all() click to toggle source

An abbreviated list of possible units. These are known combinations of atoms and prefixes. @return [Array] A list of known units @api public

# File lib/unitwise/search.rb, line 13
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

Private Class Methods

build(atom, prefix = nil) click to toggle source

Helper method for building a new unit by a known atom and prefix. @param atom [Unitwise::Atom] @param prefix [Unitwise::Prefix, nil] @return [Unitwise::Unit] @api private

# File lib/unitwise/search.rb, line 41
def build(atom, prefix = nil)
  Unit.new([Term.new(:atom => atom, :prefix => prefix)])
end