Sha256: f84a064da5c94fd31b751a07268f5f7525075af5703fd16b79eda7eff8e44e81

Contents?: true

Size: 707 Bytes

Versions: 268

Compression:

Stored size: 707 Bytes

Contents

module SafeYAML
  class Parse
    class Sexagesimal
      INTEGER_MATCHER = /\A[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+\Z/.freeze
      FLOAT_MATCHER = /\A[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+\.[0-9_]*\Z/.freeze

      def self.value(value)
        before_decimal, after_decimal = value.split(".")

        whole_part = 0
        multiplier = 1

        before_decimal = before_decimal.split(":")
        until before_decimal.empty?
          whole_part += (Float(before_decimal.pop) * multiplier)
          multiplier *= 60
        end

        result = whole_part
        result += Float("." + after_decimal) unless after_decimal.nil?
        result *= -1 if value[0] == "-"
        result
      end
    end
  end
end

Version data entries

268 entries across 246 versions & 17 rubygems

Version Path
brakeman-6.1.1 bundle/ruby/3.0.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-6.1.0 bundle/ruby/3.1.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-6.0.1 bundle/ruby/3.1.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-6.0.0 bundle/ruby/3.0.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.4.1 bundle/ruby/3.1.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.4.0 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.3.1 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.3.0 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.2.3 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.2.2 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.2.1 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.2.0 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.1.2 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.1.1 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.1.0 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.0.4 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.0.2 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.0.1 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-5.0.0 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb
brakeman-4.10.1 bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/lib/safe_yaml/parse/sexagesimal.rb