File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change 22
33module Liquid
44 module Utils
5+ DECIMAL_REGEX = /\A -?\d +\. \d +\z /
6+ UNIX_TIMESTAMP_REGEX = /\A \d +\z /
7+
58 def self . slice_collection ( collection , from , to )
69 if ( from != 0 || !to . nil? ) && collection . respond_to? ( :load_slice )
710 collection . load_slice ( from , to )
@@ -52,7 +55,7 @@ def self.to_number(obj)
5255 when Numeric
5356 obj
5457 when String
55- / \A -? \d + \. \d + \z / . match? ( obj . strip ) ? BigDecimal ( obj ) : obj . to_i
58+ DECIMAL_REGEX . match? ( obj . strip ) ? BigDecimal ( obj ) : obj . to_i
5659 else
5760 if obj . respond_to? ( :to_number )
5861 obj . to_number
@@ -73,7 +76,7 @@ def self.to_date(obj)
7376 case obj
7477 when 'now' , 'today'
7578 Time . now
76- when / \A \d + \z / , Integer
79+ when UNIX_TIMESTAMP_REGEX , Integer
7780 Time . at ( obj . to_i )
7881 when String
7982 Time . parse ( obj )
You can’t perform that action at this time.
0 commit comments