Module: Tripletexer::FormatHelpers
- Defined in:
- lib/tripletexer/format_helpers.rb
Class Method Summary collapse
Class Method Details
.format_date(value) ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/tripletexer/format_helpers.rb', line 2 def self.format_date(value) return nil if value.nil? return value.to_date.to_s if value.respond_to?(:to_date) raise TypeError, 'value must be Date, Time or String' unless value.is_a?(String) return value if value =~ /\A\d{4}-[01]\d-[0-3]\d\z/ raise ArgumentError, 'invalid date format, must be YYYY-MM-DD' end |
.normalize_body(body) ⇒ Object
10 11 12 13 14 |
# File 'lib/tripletexer/format_helpers.rb', line 10 def self.normalize_body(body) return body if body.is_a?(String) return JSON.dump(body) if body.is_a?(Hash) || body.is_a?(Array) raise ArgumentError, 'unsupported body type' end |