Class: Simrpc::Message::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/simrpc/message.rb

Overview

a single field trasnmitted via a message, containing a key / value pair

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Field

Returns a new instance of Field.



84
85
86
87
# File 'lib/simrpc/message.rb', line 84

def initialize(args = {})
  @name   = args[:name].nil?  ? "" : args[:name]
  @value  = args[:value].nil? ? "" : args[:value]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



82
83
84
# File 'lib/simrpc/message.rb', line 82

def name
  @name
end

#valueObject

Returns the value of attribute value.



82
83
84
# File 'lib/simrpc/message.rb', line 82

def value
  @value
end

Class Method Details

.from_s(data) ⇒ Object



93
94
95
96
97
98
# File 'lib/simrpc/message.rb', line 93

def self.from_s(data)
  field = Field.new
  field.name,  data = Formatter::parse_from_formatted(data)
  field.value, data = Formatter::parse_from_formatted(data)
  return field
end

Instance Method Details

#to_sObject



89
90
91
# File 'lib/simrpc/message.rb', line 89

def to_s
  Formatter::format_with_size(@name) + Formatter::format_with_size(@value)
end