Sha256: 3216e528e4c1fd9eb05af5b311302593c5c003c15f784900bb66ebe512807d0f
Contents?: true
Size: 731 Bytes
Versions: 9
Compression:
Stored size: 731 Bytes
Contents
require "chronic_duration" module Eye::Patch class ValueParser TIME_MATCHER = / (?<duration>(week|day|hour|minute|second)s?)( |\Z)/.freeze SIZE_MATCHER = / (?<size>(tera|giga|mega|kilo)?bytes?)( |\Z)/.freeze MATCHERS = { time: TIME_MATCHER, size: SIZE_MATCHER }.freeze def self.parse(value) result = MATCHERS.detect do |match_type, matcher| break send(:"parse_#{match_type}", value) if value.match(matcher) end result || value end private def self.parse_time(value) ChronicDuration.parse(value) end def self.parse_size(value) unit = value.match(SIZE_MATCHER)[:size] value.gsub(/[^\d.]/, "").to_f.send(unit) end end end
Version data entries
9 entries across 9 versions & 1 rubygems