Class: DiasporaFederation::Parsers::BaseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/diaspora_federation/parsers/base_parser.rb

Overview

BaseParser is an abstract class which is used for defining parsers for different deserialization methods.

Direct Known Subclasses

JsonParser, XmlParser

Defined Under Namespace

Classes: InvalidRootNode

Instance Method Summary collapse

Constructor Details

#initialize(entity_type) ⇒ BaseParser

Returns a new instance of BaseParser.

Parameters:

  • entity_type (Class)

    type of DiasporaFederation::Entity that we want to parse with that parser instance



9
10
11
# File 'lib/diaspora_federation/parsers/base_parser.rb', line 9

def initialize(entity_type)
  @entity_type = entity_type
end

Instance Method Details

#parseObject

This method is abstract.

This method is used to parse input with a serialized object data. It returns a comprehensive data which must be enough to construct a DiasporaFederation::Entity instance.

Since parser method output is normally passed to a .from_hash method of an entity as arguments using * operator, the parse method must return an array of a size matching the number of arguments of .from_hash method of the entity type we link with

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/diaspora_federation/parsers/base_parser.rb', line 20

def parse(*)
  raise NotImplementedError.new("you must override this method when creating your own parser")
end