Class: Perpetuity::Postgres::JSONArray

Inherits:
Object
  • Object
show all
Defined in:
lib/perpetuity/postgres/json_array.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ JSONArray

Returns a new instance of JSONArray.



8
9
10
# File 'lib/perpetuity/postgres/json_array.rb', line 8

def initialize value
  @value = value
end

Instance Method Details

#serialize_elementsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/perpetuity/postgres/json_array.rb', line 16

def serialize_elements
  @value.map do |element|
    if element.is_a? Numeric
      NumericValue.new(element)
    elsif element.is_a? String
      JSONStringValue.new(element)
    elsif element.is_a? Hash
      JSONHash.new(element, :inner)
    elsif element.is_a? JSONHash
      JSONHash.new(element.to_hash, :inner)
    end
  end.join(',')
end

#to_sObject



12
13
14
# File 'lib/perpetuity/postgres/json_array.rb', line 12

def to_s
  "'[#{serialize_elements}]'"
end