Class: Postsvg::Model::Literals::Number

Inherits:
Object
  • Object
show all
Defined in:
lib/postsvg/model/literals/number.rb

Overview

A PostScript numeric literal. Stored as a Ruby Numeric so arithmetic Just Works; class carries the original source representation choice (int vs float) when known.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Number

Returns a new instance of Number.



12
13
14
15
# File 'lib/postsvg/model/literals/number.rb', line 12

def initialize(value)
  @value = value.is_a?(Numeric) ? value : Float(value)
  freeze
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/postsvg/model/literals/number.rb', line 10

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



25
26
27
# File 'lib/postsvg/model/literals/number.rb', line 25

def ==(other)
  other.is_a?(Number) && other.value == value
end

#accept(visitor, ctx) ⇒ Object



21
22
23
# File 'lib/postsvg/model/literals/number.rb', line 21

def accept(visitor, ctx)
  visitor.visit_number(self, ctx)
end

#hashObject



30
31
32
# File 'lib/postsvg/model/literals/number.rb', line 30

def hash
  value.hash
end

#integer?Boolean

Returns:

  • (Boolean)


19
# File 'lib/postsvg/model/literals/number.rb', line 19

def integer? = value.is_a?(Integer)

#to_fObject



18
# File 'lib/postsvg/model/literals/number.rb', line 18

def to_f = value.to_f

#to_iObject



17
# File 'lib/postsvg/model/literals/number.rb', line 17

def to_i = value.to_i