Class: ServiceObjects::Parsers::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/service_objects/parsers/notification.rb

Overview

Parses and decorates a string, describing a notification

Examples:

result = ServiceObjects::Parsers::Notification.new "FOund:iTem:messages"
result.name               # => found
result.arguments          # => ["item", "messages"]
result.non_messages       # => ["item"]
result.error?             # => false
result.publish_messages?  # => true

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.initialize(source) ⇒ ServiceObjects::Parsers::Notification

Initializes the object from source string

Parameters:

  • source (#to_s)

Returns:



26
27
28
# File 'lib/service_objects/parsers/notification.rb', line 26

def initialize(source)
  @source = source.to_s
end

Instance Method Details

#argsArray<String>

The list of published values

Returns:

  • (Array<String>)


44
45
46
# File 'lib/service_objects/parsers/notification.rb', line 44

def args
  @args ||= Array(list[1..-1])
end

#error?Boolean

Checks whether a notification reports an error

Returns:

  • (Boolean)


56
57
58
# File 'lib/service_objects/parsers/notification.rb', line 56

def error?
  name == "error"
end

#exceptionString

The type of exception to be raised and catched by service object

Returns:

  • (String)


38
39
40
# File 'lib/service_objects/parsers/notification.rb', line 38

def exception
  @exception ||= name.camel_case
end

#nameString

The name for the parsed value

Returns:

  • (String)


32
33
34
# File 'lib/service_objects/parsers/notification.rb', line 32

def name
  @name ||= list.first
end

#new(source) ⇒ ServiceObjects::Parsers::Notification

Initializes the object from source string

Parameters:

  • source (#to_s)

Returns:



26
27
28
# File 'lib/service_objects/parsers/notification.rb', line 26

def initialize(source)
  @source = source.to_s
end

#non_messagesArray<String>

The list of pulished values except for messages

Returns:

  • (Array<String>)


50
51
52
# File 'lib/service_objects/parsers/notification.rb', line 50

def non_messages
  @non_messages ||= args.reject { |item| item == "messages" }
end

#order0, 1

Returns value to order notifications by

Returns:

  • (0)

    if a notification is successful

  • (1)

    if a notification is an error



69
70
71
# File 'lib/service_objects/parsers/notification.rb', line 69

def order
  @order = error? ? 1 : 0
end

#publish_messages?Boolean

Checks whether a notification publishes messages

Returns:

  • (Boolean)


62
63
64
# File 'lib/service_objects/parsers/notification.rb', line 62

def publish_messages?
  args.include? "messages"
end