lib/unitwise/expression/composer.rb in unitwise-0.8.1 vs lib/unitwise/expression/composer.rb in unitwise-0.9.0

- old
+ new

@@ -1,15 +1,19 @@ module Unitwise module Expression class Composer - attr_reader :terms - def initialize(terms) - @terms = terms + attr_reader :terms, :mode + def initialize(terms, mode) + @terms = terms + @mode = mode || :primary_code end def set @set ||= terms.reduce(SignedMultiset.new) do |s, t| - s.increment({:f => t.factor, :p => t.prefix, :a => t.atom}, t.exponent); s + identifier = { :f => t.factor, + :p => (t.prefix.to_s(mode) if t.prefix), + :a => (t.atom.to_s(mode) if t.atom) } + s.increment(identifier, t.exponent); s end end def numerator @numerator ||= set.select{|k,v| v > 0}.map do |k,v| \ No newline at end of file