Class: Jsapi::JSON::String
Overview
Represents a JSON string.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Value
Instance Method Summary collapse
-
#empty? ⇒ Boolean
:nodoc:.
-
#initialize(value, schema) ⇒ String
constructor
A new instance of String.
-
#validate(errors) ⇒ Object
:nodoc:.
Methods inherited from Value
Constructor Details
#initialize(value, schema) ⇒ String
Returns a new instance of String.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jsapi/json/string.rb', line 9 def initialize(value, schema) super(schema) @value = begin case schema.format when 'date' value.to_date when 'date-time' value.to_datetime when 'duration' ActiveSupport::Duration.parse(value) else value.to_s end rescue StandardError => e @error = e value end @value = schema.convert(@value) unless defined? @error end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/jsapi/json/string.rb', line 7 def value @value end |
Instance Method Details
#empty? ⇒ Boolean
:nodoc:
31 32 33 |
# File 'lib/jsapi/json/string.rb', line 31 def empty? # :nodoc: value.blank? end |
#validate(errors) ⇒ Object
:nodoc:
35 36 37 38 39 40 |
# File 'lib/jsapi/json/string.rb', line 35 def validate(errors) # :nodoc: return super unless defined? @error errors.add(:base, :invalid) false end |