Class: Rubyang::Xpath::BasicType::Number

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyang/xpath.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Number

Returns a new instance of Number.



97
98
99
# File 'lib/rubyang/xpath.rb', line 97

def initialize value
  @value = Float(value)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



96
97
98
# File 'lib/rubyang/xpath.rb', line 96

def value
  @value
end

Instance Method Details

#!=(right) ⇒ Object



161
162
163
164
165
166
167
168
169
# File 'lib/rubyang/xpath.rb', line 161

def != right
  case right
  when Number
    value = (@value != right.value)
    Boolean.new value
  else
    raise
  end
end

#*(right) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/rubyang/xpath.rb', line 131

def * right
  case right
  when Number
    value = (@value * right.value)
    Number.new value
  else
    raise
  end
end

#+(right) ⇒ Object



111
112
113
114
115
116
117
118
119
# File 'lib/rubyang/xpath.rb', line 111

def + right
  case right
  when Number
    value = (@value + right.value)
    Number.new value
  else
    raise
  end
end

#-(right) ⇒ Object



121
122
123
124
125
126
127
128
129
# File 'lib/rubyang/xpath.rb', line 121

def - right
  case right
  when Number
    value = (@value - right.value)
    Number.new value
  else
    raise
  end
end

#-@Object



106
107
108
109
# File 'lib/rubyang/xpath.rb', line 106

def -@
  value = (- @value)
  Number.new value
end

#/(right) ⇒ Object



141
142
143
144
145
146
147
148
149
# File 'lib/rubyang/xpath.rb', line 141

def / right
  case right
  when Number
    value = (@value / right.value)
    Number.new value
  else
    raise
  end
end

#==(right) ⇒ Object



151
152
153
154
155
156
157
158
159
# File 'lib/rubyang/xpath.rb', line 151

def == right
  case right
  when Number
    value = (@value == right.value)
    Boolean.new value
  else
    raise
  end
end

#to_booleanObject



101
102
103
104
# File 'lib/rubyang/xpath.rb', line 101

def to_boolean
  value = if @value == Float(0) then false else true end
  Boolean.new value
end