Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/m500.rb
Instance Method Summary collapse
- #append_K(a) ⇒ Object
- #is_Dec? ⇒ Boolean
- #is_f? ⇒ Boolean
- #is_Frac? ⇒ Boolean
- #is_K? ⇒ Boolean
- #is_K_Leicht? ⇒ Boolean
- #is_N0? ⇒ Boolean
- #is_N? ⇒ Boolean
- #is_Q? ⇒ Boolean
- #is_R? ⇒ Boolean
- #is_r? ⇒ Boolean
- #is_Sig? ⇒ Boolean
- #is_Z? ⇒ Boolean
- #to_Dec ⇒ Object
- #to_Frac ⇒ Object
- #to_K ⇒ Object
- #to_N ⇒ Object
- #to_N0 ⇒ Object
- #to_Q ⇒ Object
- #to_Sig ⇒ Object
- #to_ST ⇒ Object
- #to_Z ⇒ Object
Instance Method Details
#append_K(a) ⇒ Object
234 235 236 237 |
# File 'lib/m500.rb', line 234 def append_K(a) a = a.to_Frac self.gsub!("&&&&","Fraction(Zahlen(#{a.integer.to_s}),Quotient(Zahlen(#{a.properfraction.numerator.to_s}),Zahlen(#{a.properfraction.denominator.to_s})))") end |
#is_Dec? ⇒ Boolean
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/m500.rb', line 100 def is_Dec? t = true re = /(^-?[0-9]+)\\#{Decimal::decimalSeparator}([0-9]+)/ re = /(^-?[0-9]+)\.([0-9]+)/ md = re.match(self.to_s) if md.nil? t = false else t = false if md[1].nil? && md[2].nil? && md[3].nil? end t end |
#is_f? ⇒ Boolean
53 54 55 56 57 58 59 |
# File 'lib/m500.rb', line 53 def is_f? t = true re = /(\-*\d+).(\d+)e([-|+])(\d+)/ md = re.match(self) t = false if md[1].nil? && md[2].nil? && md[3].nil? && md[4].nil? t end |
#is_Frac? ⇒ Boolean
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/m500.rb', line 89 def is_Frac? t = true re = /(^-?[0-9]+) ([0-9]+)\/([0-9]+)/ md = re.match(self) if md.nil? t = false else t = false if md[1].nil? && md[2].nil? && md[3].nil? && md[4].nil? end t end |
#is_K? ⇒ Boolean
220 221 222 223 224 225 226 |
# File 'lib/m500.rb', line 220 def is_K? t = true re = /(\d+)#{Kettenbruch::Separator}(\d+)/ md = re.match(self) t = false if md[1].nil? && md[2].nil? t end |
#is_K_Leicht? ⇒ Boolean
227 228 229 230 231 232 233 |
# File 'lib/m500.rb', line 227 def is_K_Leicht? t = true re = /(\d+)#{Kettenbruch::Separator}(\d+)/ md = re.match(self) t = false if md[1].nil? && md[2].nil? t end |
#is_N0? ⇒ Boolean
66 67 68 69 70 71 |
# File 'lib/m500.rb', line 66 def is_N0? re = /(^[0-9]+)$/ md = re.match(self.to_s) t = emptySet t = md[1].to_i.to_N unless md.nil? end |
#is_N? ⇒ Boolean
60 61 62 63 64 65 |
# File 'lib/m500.rb', line 60 def is_N? re = /(^[0-9]+)$/ md = re.match(self.to_s) t = emptySet t = md[1].to_i.to_N unless md.nil? end |
#is_Q? ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/m500.rb', line 39 def is_Q? t = true re = /(\d+)\/(\d+)/ md = re.match(self) if md.nil? then t = is_Z? else t = false if md[1].nil? && md[2].nil? && md[3].nil? && md[4].nil? end t end |
#is_R? ⇒ Boolean
114 115 116 |
# File 'lib/m500.rb', line 114 def is_R? false end |
#is_r? ⇒ Boolean
50 51 52 |
# File 'lib/m500.rb', line 50 def is_r? Rational(self).kind_of?(Rational) end |
#is_Sig? ⇒ Boolean
112 113 |
# File 'lib/m500.rb', line 112 def is_Sig? end |
#is_Z? ⇒ Boolean
72 73 74 75 76 77 |
# File 'lib/m500.rb', line 72 def is_Z? re = /(^-?[0-9]+)$/ md = re.match(self.to_s) t = emptySet t = Zahlen(md[1].to_i) unless md.nil? end |
#to_Dec ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/m500.rb', line 147 def to_Dec re = /^-/ md = re.match(self.to_s) e = -1 e = 1 if md.to_a.empty? md = nil t0 = 0 t1 = '0' t2 = nil t3 = nil re = /([0-9]+)#{Decimal::decimalSeparator}([0-9]+)\[([0-9]+)\]/ re = /([0-9]+)\.([0-9]+)\[([0-9]+)\]/ md = re.match(self.to_s) if md.to_a.empty? then re = /([0-9]+)#{Decimal::decimalSeparator}([0-9]+)/ re = /([0-9]+)\.([0-9]+)/ md = re.match(self.to_s) if md.to_a.empty? then re = /([0-9]+)#{Decimal::decimalSeparator}\[([0-9]+)\]/ re = /([0-9]+)\.\[([0-9]+)\]/ md = re.match(self.to_s) if md.to_a.empty? then re = /([0-9]+)/ md = re.match(self.to_s) t0 = 0 t1 = '0' t2 = nil t3 = md[1].to_i else t0 = 0 t1 = md[2] #.to_i t2 = nil t3 = md[1].to_i end else t0 = md[2].scan(/^0+/)[0].length unless md[2].scan(/^0+/).empty? t1 = md[3] unless md[3].nil? t2 = md[2].to_i t3 = md[1].to_i end else t0 = md[2].scan(/^0+/)[0].length unless md[2].scan(/^0+/).empty? t1 = md[3] unless md[3].nil? t2 = md[2].to_i t3 = md[1].to_i end Decimal(t3,t2,t1,t0,e) end |
#to_Frac ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/m500.rb', line 195 def to_Frac re = /(^[0-9]+) ([0-9]+)\/([0-9]+)/ md = re.match(self.to_s) t = nil if not md.nil? then t = Fraction(Zahlen(md[1].to_i),Quotient(md[2].to_i, md[3].to_i)) else re = /^-1\(([0-9]+) ([0-9]+)\/([0-9]+)\)/ md = re.match(self.to_s) if not md.nil? then t = Fraction(Zahlen(md[1].to_i),Quotient(md[2].to_i, md[3].to_i),-1) unless md.nil? else re = /(\-*[0-9]+)\/([0-9]+)/ md = re.match(self.to_s) if not md.nil? then t = Fraction(Quotient(Zahlen(md[1].to_i),Natural(md[2].to_i))) else t=Fraction(Quotient(self.to_i,1)) end end end end |
#to_K ⇒ Object
238 239 240 241 242 243 244 245 |
# File 'lib/m500.rb', line 238 def to_K a = self.split(";") int = a.at(0).to_i re = /'...'/ md = re.match(a.at(1)) frK = eval("[" + a.at(1).gsub("...","") + "]" ) ([int] + frK).to_K end |
#to_N ⇒ Object
117 118 119 120 121 122 |
# File 'lib/m500.rb', line 117 def to_N re = /(^[0-9]+)/ md = re.match(self.to_s) t = emptySet t = md[1].to_i.to_N unless md.nil? end |
#to_N0 ⇒ Object
123 124 125 126 127 128 |
# File 'lib/m500.rb', line 123 def to_N0 re = /(^[0-9]+)/ md = re.match(self.to_s) t = emptySet t = md[1].to_i.to_N0 unless md.nil? end |
#to_Q ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/m500.rb', line 135 def to_Q re = /(-?[0-9]+)\/([0-9]+)/ md = re.match(self.to_s) ret = naught if md then t = 1 Natural(md[2].to_i).kind_of?(EmptySetClass) ? ret = infinity : ret = Quotient(Zahlen(md[1].to_i),Natural(md[2].to_i)) else Natural(md[2].to_i).kind_of?(EmptySetClass) ? ret = infinity : ret = Quotient(Zahlen(md[1].to_i),Natural(md[2].to_i)) end ret end |
#to_Sig ⇒ Object
246 247 |
# File 'lib/m500.rb', line 246 def to_Sig end |