class NRSER::Types::ArrayType
Arrays!
@note
Construct {ArrayType} types using the {.Array} factory.
@todo
Just call this Array?! Combine with arrays of a type?!
Constants
- DEFAULT_SPLIT_WITH
Default value to split strings with in {#from_s} if the string provided does is not recognized as an encoding format (as of writing, JSON is the only format we attempt to detect).
Splits
Public Class Methods
new(split_with: DEFAULT_SPLIT_WITH, **options)
click to toggle source
Calls superclass method
# File lib/nrser/types/arrays.rb, line 42 def initialize split_with: DEFAULT_SPLIT_WITH, **options super ::Array, **options @split_with = split_with end
Public Instance Methods
custom_from_s(string)
click to toggle source
# File lib/nrser/types/arrays.rb, line 86 def custom_from_s string # Does it looks like a JSON array? if NRSER.looks_like_json_array? string # It does! Load it begin return JSON.load( string ) rescue # pass - if we failed to load as JSON, it may just not be JSON, and # we can try the split approach below. end end # Split it with the splitter and check that items_from_strings( string.split( @split_with ) ) end
default_name()
click to toggle source
@!group Display Instance Methods
# File lib/nrser/types/arrays.rb, line 54 def default_name if item_type == NRSER::Types.Top 'Array' else "Array<#{ item_type.name }>" end end
default_symbolic()
click to toggle source
# File lib/nrser/types/arrays.rb, line 63 def default_symbolic "[#{ item_type.symbolic }]" end
item_type()
click to toggle source
# File lib/nrser/types/arrays.rb, line 48 def item_type; NRSER::Types.Top; end
items_from_strings(items)
click to toggle source
Called on an array of string items that have been split from a single string by {#from_s} to convert each individual item before {#check} is called on the value.
{NRSER::Types::ArrayType} implementation is a no-op that just returns `items` - this method is in place for subclasses to override.
@param [Array<String>] items
@return [Array]
# File lib/nrser/types/arrays.rb, line 81 def items_from_strings items items end