Sha256: 0f090af3e5a025b1373c6a2a571b1672e60022db04205c0ae1faa023f5f3c385

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

module Danica
  class Operator
    class Chained < Operator
      def to_f
        chain(variables.map(&:to_f))
      end

      def include?(value)
        value = wrap_value(value)
        variables.include?(value)
      end

      def to_tex
        to_string(:tex)
      end

      def to_gnu
        to_string(:gnu)
      end

      private

      def to_string(type)
        extractor = string_extractor("to_#{type}")
        symbol = { tex: tex_symbol, gnu: gnu_symbol }[type]
        variables.procedural_join(extractor, &join_proc(symbol))
      end

      def join_proc(symbol)
        proc { " #{symbol} " }
      end

      def string_extractor(method)
        proc do |parcel|
          parcel = wrap_as_group(parcel)
          parcel.public_send(method)
        end
      end

      def repack(other)
        other_variables = other.is_a?(self.class) ? other.variables : [ other ]
        self.class.new(variables + other_variables)
      end

      def chain(numbers)
        numbers.inject do |a,b|
          chain_operation(a,b)
        end.to_f
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
danica-2.3.1 lib/danica/operator/chained.rb
danica-2.3.0 lib/danica/operator/chained.rb
danica-2.2.1 lib/danica/operator/chained.rb
danica-2.2.0 lib/danica/operator/chained.rb
danica-2.1.1 lib/danica/operator/chained.rb
danica-2.1.0 lib/danica/operator/chained.rb
danica-2.0.6 lib/danica/operator/chained.rb