Sha256: 458a3112dcf6cf7df45dd9f507e3efa2d52a6053d60643a56a1fdef3692a76db

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module Danica
  class Function
    include ActiveModel::Model
  
    require 'danica/function/chained'
    require 'danica/function/product'
    require 'danica/function/sum'
    require 'danica/function/division'
    require 'danica/function/power'
    require 'danica/function/square_root'
  
    attr_accessor :name, :variables
  
    def to_f
      raise 'Not IMplemented yet'
    end
  
    def to_tex
      Number.new(to_f).to_tex
    rescue Exception::NotDefined
      tex_string
    end

    def to_gnu
      Number.new(to_f).to_gnu
    rescue Exception::NotDefined
      gnu_string
    end
  
    def variables=(variables)
      @variables = variables.map { |v| wrap_value(v) }
    end
  
    def valued?
      to_f.presend?
    rescue Exception::NotDefined
      false
    end
  
    private
  
    def tex_string
      raise 'Not IMplemented yet'
    end

    def gnu_string
      raise 'Not IMplemented yet'
    end
  
    def wrap_value(value)
      return Number.new(value) if value.is_a?(Numeric)
      return Variable.new(value) if value.is_a?(Hash)
      return Variable.new(name: value) if [ String, Symbol ].any? { |c| value.is_a?(c) }
      value
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danica-1.0.0 lib/danica/function.rb