Sha256: 8c64c2d04b3e05c3019a800abc2788394ddc028d4de5d6713e74d7793f5978e1

Contents?: true

Size: 1.07 KB

Versions: 1

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

      private

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

      def tex_string
        (numeric_to_tex + non_numeric_variables.map(&:to_tex)).join(" #{tex_symbol} ")
      end

      def gnu_string
        (numeric_to_tex + non_numeric_variables.map(&:to_gnu)).join(" #{gnu_symbol} ")
      end

      def numeric_variables
        variables.select { |v| v.valued? }
      end

      def non_numeric_variables
        variables.reject { |v| v.valued? }
      end

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

      def numeric_to_tex
        return [] if numeric_variables.empty?
        [ Number.new(chain(numeric_variables.map(&:to_f))).to_tex ]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danica-2.0.4 lib/danica/operator/chained.rb