Sha256: 0409b7e6ffd32686d7aa2541153253f281fe4dda33ebb2812e87c7aab8a79027

Contents?: true

Size: 992 Bytes

Versions: 8

Compression:

Stored size: 992 Bytes

Contents

module Danica
  module Wrapper
    def wrap_value(value)
      Wrapper.wrap_value(value)
    end

    def self.wrap_value(value)
      case value
      when Numeric
        wrap_numeric(value)
      when Hash
        wrap_hash(value)
      when String, Symbol, NilClass
        Variable.new(name: value)
      else
        value
      end
    end

    def self.wrap_numeric(number)
      return Negative.new(Number.new(-number)) if number < 0
      Number.new(number)
    end

    def self.wrap_hash(hash)
      return Constant.new(hash) if hash.keys.map(&:to_sym).sort == %i(gnu latex value)
      Variable.new(hash)
    end

    autoload :Number,    'danica/wrapper/number'
    autoload :Group,     'danica/wrapper/group'
    autoload :Negative,  'danica/wrapper/negative'
    autoload :PlusMinus, 'danica/wrapper/plus_minus'
    autoload :Constant,  'danica/wrapper/constant'
    autoload :Variable,  'danica/wrapper/variable'
    autoload :Container, 'danica/wrapper/container'
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
danica-2.6.4 lib/danica/wrapper.rb
danica-2.6.3 lib/danica/wrapper.rb
danica-2.6.2 lib/danica/wrapper.rb
danica-2.6.1 lib/danica/wrapper.rb
danica-2.6.0 lib/danica/wrapper.rb
danica-2.5.1 lib/danica/wrapper.rb
danica-2.5.0 lib/danica/wrapper.rb
danica-2.4.4 lib/danica/wrapper.rb