Class: String

Inherits:
Object show all
Defined in:
lib/kaki/utils/imgsuffix.rb,
lib/kaki/utils/rec_decimal.rb

Instance Method Summary collapse

Instance Method Details

#__to_r__Object


29
# File 'lib/kaki/utils/rec_decimal.rb', line 29

alias :__to_r__ :to_r

#imgsuffixString

拡張子が画像ならばその拡張子を返す

Returns:


4
5
6
7
8
9
# File 'lib/kaki/utils/imgsuffix.rb', line 4

def imgsuffix
  [".jpg", ".gif", ".png", ".jpeg", ".bmp", ".JPG", ".GIF", ".PNG", ".JPEG", ".BMP"].each do |sf|
    return sf if include?(sf)
  end
  ""
end

#to_rRational

循環小数を分数に直す

Returns:


32
33
34
35
36
37
38
39
40
41
# File 'lib/kaki/utils/rec_decimal.rb', line 32

def to_r
  st = delete(" ")
  return st.__to_r__ unless (m = /^([^\d]?)(\d+)\.(\d*)\((\d+)\)$/.match(st))
  f = (m[1] == "-") ? -1 : 1
  
  result = (m[2] + "." + m[3]).__to_r__
  l = m[4].length
  result += Rational(m[4].to_i, 10 ** l - 1) * Rational(1, 10) ** m[3].length
  result * f
end