Sha256: 6941d5c0725ed442812afcd055c0a01649bc9bdbd604de2455e8d5ee4b3377f5

Contents?: true

Size: 696 Bytes

Versions: 1

Compression:

Stored size: 696 Bytes

Contents

# frozen_string_literal: true

module Danica
  class Wrapper::Number
    include BaseOperations
    include Common

    attr_accessor :value

    default_value :priority, 10
    delegate :to_f, to: :value
    default_value :is_grouped?, false

    def initialize(value)
      @value = value
    end

    def to(_format, decimals: nil, **_options)
      return value.to_i.to_s if value.to_i == value
      return format("%.#{decimals}f", value).to_f.to_s if decimals
      value.to_s
    end

    def valued?
      value.present?
    end

    def signaled?
      value < 0
    end

    def ==(other)
      return false unless other.class == self.class
      value == other.value
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danica-2.7.5 lib/danica/wrapper/number.rb