Class: Jekyll::JekyllRdf::Types::XsdDouble
- Inherits:
-
Object
- Object
- Jekyll::JekyllRdf::Types::XsdDouble
- Defined in:
- lib/jekyll/types/XsdDouble.rb
Constant Summary collapse
- @@class_uri =
"http://www.w3.org/2001/XMLSchema#double"
Class Method Summary collapse
- .===(other) ⇒ Object
- .match?(string) ⇒ Boolean
- .regex ⇒ Object
- .to_s ⇒ Object
- .to_type(string) ⇒ Object
Class Method Details
.===(other) ⇒ Object
33 34 35 |
# File 'lib/jekyll/types/XsdDouble.rb', line 33 def self.=== other return other.to_s.eql? @@class_uri end |
.match?(string) ⇒ Boolean
7 8 9 |
# File 'lib/jekyll/types/XsdDouble.rb', line 7 def self.match? string return regex.match string.upcase end |
.regex ⇒ Object
11 12 13 14 |
# File 'lib/jekyll/types/XsdDouble.rb', line 11 def self.regex @@regex ||= /^[+-]?[0-9]+\.(\d+)E[+-]?(\d+)$/ return @@regex end |
.to_s ⇒ Object
37 38 39 |
# File 'lib/jekyll/types/XsdDouble.rb', line 37 def self.to_s return @@class_uri end |
.to_type(string) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jekyll/types/XsdDouble.rb', line 16 def self.to_type string string = string.upcase number = string.to_f negative = number < 0 if negative number = number * (-1) end e = [-1 * (Math.log10(number).floor - (string.to_s.index('E') - string.to_s.index('.'))), 0].max vz = "" if negative vz = "-" end result = vz.to_s + sprintf("%." + e.to_s + "f", number) return result end |