Class: Protobuf::Field::FieldArray

Inherits:
Array
  • Object
show all
Defined in:
lib/protobuf/field/field_array.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field) ⇒ FieldArray

Constructor



15
16
17
# File 'lib/protobuf/field/field_array.rb', line 15

def initialize(field)
  @field = field
end

Instance Attribute Details

#fieldObject (readonly)

Attributes



9
10
11
# File 'lib/protobuf/field/field_array.rb', line 9

def field
  @field
end

Instance Method Details

#<<(val) ⇒ Object



27
28
29
# File 'lib/protobuf/field/field_array.rb', line 27

def <<(val)
  super(normalize(val)) unless val.nil?
end

#[]=(nth, val) ⇒ Object

Public Instance Methods



23
24
25
# File 'lib/protobuf/field/field_array.rb', line 23

def []=(nth, val)
  super(nth, normalize(val)) unless val.nil?
end

#push(val) ⇒ Object



31
32
33
# File 'lib/protobuf/field/field_array.rb', line 31

def push(val)
  super(normalize(val)) unless val.nil?
end

#replace(val) ⇒ Object



35
36
37
38
39
# File 'lib/protobuf/field/field_array.rb', line 35

def replace(val)
  raise_type_error(val) unless val.is_a?(Array)
  val.map! { |v| normalize(v) }
  super(val)
end

#to_hash_valueObject

Return a hash-representation of the given values for this field type. The value in this case would be an array.



43
44
45
46
47
# File 'lib/protobuf/field/field_array.rb', line 43

def to_hash_value
  self.map do |value|
    value.respond_to?(:to_hash_value) ? value.to_hash_value : value
  end
end

#to_sObject



49
50
51
# File 'lib/protobuf/field/field_array.rb', line 49

def to_s
  "[#{field.name}]"
end

#unshift(val) ⇒ Object



53
54
55
# File 'lib/protobuf/field/field_array.rb', line 53

def unshift(val)
  super(normalize(val)) unless val.nil?
end