Class: ST
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Numeric
#irrational?, #rational?, #sgml_id, #to_Dec, #to_Frac, #to_K, #to_N, #to_N0, #to_Q, #to_R, #to_Sig, #to_Z, #to_sgml
Methods included from SGML
#sgml_id, #tog_sgml_id
Constructor Details
#initialize(a, b = 0, c = 't') ⇒ ST
501
502
503
504
505
506
507
508
509
510
|
# File 'lib/m500.rb', line 501
def initialize(a,b=0,c='t') if a.kind_of?(String)
regex = /(\d+[a-z])*(\+)?(\d+)?/
m = regex.match(a)
n = /(\d+)([a-z])/.match(m[1]) if m[1]
@a = [n.nil? ? 0 : n[1] ? n[1] : 0, m[3] ? m[3] : 0, n.nil? ? c : n[2] ? n[2] : 0]
else
@a = [a,b,c]
end
end
|
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a.
511
512
513
|
# File 'lib/m500.rb', line 511
def a
@a
end
|
Instance Method Details
#*(o) ⇒ Object
521
522
523
524
525
526
527
528
529
|
# File 'lib/m500.rb', line 521
def *(o)
if o.kind_of?(ST) then
"#{@a.at(0).to_i*o.a.at(0).to_i}#{@a.at(2)}+#{@a.at(1).to_i*o.a.at(1)}"
elsif o == 0
"0"
else
"#{@a.at(0).to_i*o}#{@a.at(2)}+#{@a.at(1).to_i*o}" if o.kind_of?(Numeric)
end
end
|
#+(o) ⇒ Object
512
513
514
515
516
517
518
519
520
|
# File 'lib/m500.rb', line 512
def +(o)
if o.kind_of?(ST) then
"#{@a.at(0).to_i+o.a.at(0).to_i}#{@a.at(2)}+#{@a.at(1).to_i+o.a.at(1).to_i}"
elsif o == 0
self
else
a.at(0).to_i ==0 ? o : "#{@a.at(0)}#{@a.at(2)}+#{@a.at(1).to_i+o}" if o.kind_of?(Numeric)
end
end
|
#-(o) ⇒ Object
530
531
532
533
534
535
536
|
# File 'lib/m500.rb', line 530
def -(o)
if o.kind_of?(ST) then
"#{@a.at(0).to_i-o.a.at(0).to_i}#{@a.at(2)}+#{@a.at(1)-o.a.at(1)}"
else
"#{@a.at(0)}#{@a.at(2)}+#{@a.at(1)-o}" if o.kind_of?(Numeric)
end
end
|
#/(o) ⇒ Object
537
538
539
540
541
542
543
544
545
|
# File 'lib/m500.rb', line 537
def /(o)
if o.kind_of?(ST) then
"#{@a.at(0).to_i/o.a.at(0).to_i}#{@a.at(2)}+#{@a.at(1).to_i/o.a.at(1)}"
elsif o == 0
"OO"
else
"#{@a.at(0).to_i/o}#{@a.at(2)}+#{@a.at(1).to_i/o}" if o.kind_of?(Numeric)
end
end
|
#coerce(o) ⇒ Object
546
547
548
|
# File 'lib/m500.rb', line 546
def coerce(o)
[self, o]
end
|
#inspect ⇒ Object
552
553
554
|
# File 'lib/m500.rb', line 552
def inspect
"'#{@a.at(0)}#{@a.at(2)}+#{@a.at(1)}'.to_ST"
end
|
#to_s ⇒ Object
549
550
551
|
# File 'lib/m500.rb', line 549
def to_s
"'#{@a.at(0)}#{@a.at(2)}+#{@a.at(1)}'"
end
|