Class: WebFunction::Type::ArrayOf

Inherits:
Object
  • Object
show all
Defined in:
lib/web_function/type/array_of.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(of) ⇒ ArrayOf

Returns a new instance of ArrayOf.



8
9
10
11
# File 'lib/web_function/type/array_of.rb', line 8

def initialize(of)
  @base_type = "array"
  @of = of
end

Instance Attribute Details

#base_typeObject (readonly)

Returns the value of attribute base_type.



6
7
8
# File 'lib/web_function/type/array_of.rb', line 6

def base_type
  @base_type
end

#ofObject (readonly)

Returns the value of attribute of.



6
7
8
# File 'lib/web_function/type/array_of.rb', line 6

def of
  @of
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



36
37
38
# File 'lib/web_function/type/array_of.rb', line 36

def ==(other)
  other.is_a?(ArrayOf) && other.of == @of
end

#format(format = :default) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/web_function/type/array_of.rb', line 21

def format(format = :default)
  case format
  when :base
    "array"
  when :compact, :default
    "array<#{@of.format(format)}>"
  else
    raise ArgumentError, "unknown format: #{format.inspect}"
  end
end

#hashObject



41
42
43
# File 'lib/web_function/type/array_of.rb', line 41

def hash
  [ArrayOf, @of].hash
end

#inspectObject



17
18
19
# File 'lib/web_function/type/array_of.rb', line 17

def inspect
  "#<ArrayOf #{@of.inspect}>"
end

#objectsObject



45
46
47
# File 'lib/web_function/type/array_of.rb', line 45

def objects
  @of.objects
end

#refinementObject



13
14
15
# File 'lib/web_function/type/array_of.rb', line 13

def refinement
  nil
end

#to_sObject



32
33
34
# File 'lib/web_function/type/array_of.rb', line 32

def to_s
  format(:default)
end

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/web_function/type/array_of.rb', line 53

def valid?(value)
  value.is_a?(Array) && value.all? { |element| @of.valid?(element) }
end

#without_refinementsObject



49
50
51
# File 'lib/web_function/type/array_of.rb', line 49

def without_refinements
  ArrayOf.new(@of.without_refinements)
end