Class: VCDOM::XPath::Internal::NumberValue

Inherits:
AbstractValue show all
Defined in:
lib/vcdom/xpath/internal/value.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractValue

#<, #<=, #<=>, #==, #>, #>=, #is_command?, #is_expr?, #is_value?, #neq?, #to_s, #|

Constructor Details

#initialize(val) ⇒ NumberValue

Returns a new instance of NumberValue.



72
73
74
# File 'lib/vcdom/xpath/internal/value.rb', line 72

def initialize( val )
  @value = val.to_f
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



112
113
114
# File 'lib/vcdom/xpath/internal/value.rb', line 112

def value
  @value
end

Instance Method Details

#%(val) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/vcdom/xpath/internal/value.rb', line 122

def %( val )
  value1 = val.to_number_value.value
  value1 < 0 && value1 = -value1
  value2 = @value
  if value2 < 0 then
    value2 = - value2
    value2 %=  value1
    value2 = - value2
  else
    value2 %=  value1
  end
  NumberValue.new( value2 )
end

#*(val) ⇒ Object



120
# File 'lib/vcdom/xpath/internal/value.rb', line 120

def *( val ); NumberValue.new( @value * val.to_number_value.value ) end

#+(val) ⇒ Object



118
# File 'lib/vcdom/xpath/internal/value.rb', line 118

def +( val ); NumberValue.new( @value + val.to_number_value.value ) end

#-(val) ⇒ Object



119
# File 'lib/vcdom/xpath/internal/value.rb', line 119

def -( val ); NumberValue.new( @value - val.to_number_value.value ) end

#-@Object

define operations



117
# File 'lib/vcdom/xpath/internal/value.rb', line 117

def -@(); @value = - @value; self end

#/(val) ⇒ Object



121
# File 'lib/vcdom/xpath/internal/value.rb', line 121

def /( val ); NumberValue.new( @value / val.to_number_value.value ) end

#to_boolean_valueObject

数値は、正または負のゼロでなくNaNでもない場合に、かつない場合にのみ、真である。



108
109
110
# File 'lib/vcdom/xpath/internal/value.rb', line 108

def to_boolean_value()
  ( @value.zero? || @value.nan? ) ? BooleanValue.false : BooleanValue.true
end

#to_number_valueObject



103
104
105
# File 'lib/vcdom/xpath/internal/value.rb', line 103

def to_number_value()
  self
end

#to_string_valueObject

NaN -> “NaN” 正ゼロ, 負ゼロ -> “0” 正の無限大 -> “Infinity” 負の無限大 -> “-Infinity” 数値が整数である場合, 数値は 10 進形式で, 小数点がなく先頭のゼロもない [0-9]+ として表現され, 数値が負である場合には負号 (-) が前につくそれ以外 -> 数値は 10 進形式で [0-9]+ “.” [0-9]+ として表現され, 数値が負である場合には負号 (-) が前につく小数点の直前にある必須の数字 1 個を別として, 小数点の前に先頭のゼロがあってはならない. 小数点の後の必須の数字1個を越えてそれ以上の数字は, その数値をその他すべての IEEE 754 数値から一意的に区別するのに必要な数字がなければならないが, 必要なだけしかあってはならない



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/vcdom/xpath/internal/value.rb', line 86

def to_string_value()
  if @value.nan? then
    str = StringValue.new("NaN")
  elsif @value.infinite? == 1 then
    str = StringValue.new("Infinity")
  elsif @value.infinite? == -1 then
    str = StringValue.new("-Infinity")
  elsif @value.zero? then
    str = StringValue.new("0")
  elsif @value.truncate == @value then
    str = StringValue.new(@value.to_i.to_s)
  else
    str = StringValue.new(@value.to_s)
  end
  str
end

#value_typeObject



113
# File 'lib/vcdom/xpath/internal/value.rb', line 113

def value_type; :number end