lib/schemacop/v3/string_node.rb in schemacop-3.0.13 vs lib/schemacop/v3/string_node.rb in schemacop-3.0.14
- old
+ new
@@ -7,19 +7,20 @@
format
].freeze
# rubocop:disable Layout/LineLength
FORMAT_PATTERNS = {
- date: /^([0-9]{4})-?(1[0-2]|0[1-9])-?(3[01]|0[1-9]|[12][0-9])$/,
- 'date-time': /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$/,
- time: /^(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$/,
- email: URI::MailTo::EMAIL_REGEXP,
- boolean: /^(true|false|0|1)$/,
- binary: nil,
- symbol: nil,
- integer: /^-?[0-9]+$/,
- number: /^-?[0-9]+(\.[0-9]+)?$/
+ date: /^([0-9]{4})-?(1[0-2]|0[1-9])-?(3[01]|0[1-9]|[12][0-9])$/,
+ 'date-time': /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$/,
+ time: /^(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$/,
+ email: URI::MailTo::EMAIL_REGEXP,
+ boolean: /^(true|false|0|1)$/,
+ binary: nil,
+ symbol: nil,
+ integer: /^-?[0-9]+$/,
+ number: /^-?[0-9]+(\.[0-9]+)?$/,
+ 'integer-list': /^(-?[0-9]+)(,-?[0-9]+)*$/
}.freeze
# rubocop:enable Layout/LineLength
def self.allowed_options
super + ATTRIBUTES + %i[format_options pattern allow_blank]
@@ -90,20 +91,22 @@
return nil
end
case options[:format]
when :boolean
- return to_cast == 'true' || to_cast == '1'
+ %w[true 1].include?(to_cast)
when :date
return Date.parse(to_cast)
when :'date-time'
return DateTime.parse(to_cast)
when :time
Time.parse(to_cast)
when :integer
return Integer(to_cast)
when :number
return Float(to_cast)
+ when :'integer-list'
+ return to_cast.split(',').map(&:to_i)
when :symbol
return to_cast.to_sym
else
return to_cast
end