Class: Inthegra::BaseSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/inthegra/serializer/base.rb

Overview

Generic serialize class

Direct Known Subclasses

CollectionSerializer, VehiclesSerializer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, model) ⇒ BaseSerializer

Initialize the serializer passing a input data and a model

Parameters:

  • input (String)

    The input data

  • model (String)

    The resource model



18
19
20
21
22
23
24
25
26
27
# File 'lib/inthegra/serializer/base.rb', line 18

def initialize(data, model)
  data ||= []

  unless data.is_a?(Array)
    raise InvalidSerializerInput, "The data is a #{data.class} and not a Array type"
  end

  @model = model
  @input = data
end

Instance Attribute Details

#inputArray:Hash (readonly)

Returns the input data.

Returns:

  • (Array:Hash)

    the input data



6
7
8
# File 'lib/inthegra/serializer/base.rb', line 6

def input
  @input
end

#modelBaseModel (readonly)

Returns the model of collection.

Returns:



12
13
14
# File 'lib/inthegra/serializer/base.rb', line 12

def model
  @model
end

#outputArray:BaseModel (readonly)

Returns the output data.

Returns:

  • (Array:BaseModel)

    the output data



9
10
11
# File 'lib/inthegra/serializer/base.rb', line 9

def output
  @output
end

Class Method Details

.parse(input, model) ⇒ Object

Decorator method for the serializer

Examples:

Parse a line response

Inthegra::CollectionSerializer(response, Inthegra::Line)

Parameters:

  • input (String)

    The input data

  • model (String)

    the model of collection



35
36
37
# File 'lib/inthegra/serializer/base.rb', line 35

def self.parse(input, model)
  @output = new(input, model).parse
end

Instance Method Details

#parseObject

Implementation of the parser

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/inthegra/serializer/base.rb', line 40

def parse
  raise NotImplementedError.new
end