Class: Nis::Struct::Message

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

Constant Summary collapse

TYPE_PLAIN =
1
TYPE_ENCRYPTED =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = '') ⇒ Message

Returns a new instance of Message.



11
12
13
14
# File 'lib/nis/struct/message.rb', line 11

def initialize(value = '')
  @value = value
  @type  = TYPE_PLAIN
end

Instance Attribute Details

#payloadString

Returns the current value of payload.

Returns:

  • (String)

    the current value of payload



5
6
7
# File 'lib/nis/struct/message.rb', line 5

def payload
  @payload
end

#typeInteger

Returns the current value of type.

Returns:

  • (Integer)

    the current value of type



5
6
7
# File 'lib/nis/struct/message.rb', line 5

def type
  @type
end

#valueString

Returns the current value of value.

Returns:

  • (String)

    the current value of value



5
6
7
# File 'lib/nis/struct/message.rb', line 5

def value
  @value
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/nis/struct/message.rb', line 47

def ==(other)
  @value == other.value
end

#bytesizeInteger

Returns:

  • (Integer)


27
28
29
# File 'lib/nis/struct/message.rb', line 27

def bytesize
  payload.bytesize
end

#encrypted?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/nis/struct/message.rb', line 17

def encrypted?
  @type == TYPE_ENCRYPTED
end

#plain?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/nis/struct/message.rb', line 22

def plain?
  @type == TYPE_PLAIN
end

#to_hashHash

Returns:

  • (Hash)


37
38
39
# File 'lib/nis/struct/message.rb', line 37

def to_hash
  { payload: payload, type: @type }
end

#to_sString

Returns:

  • (String)


42
43
44
# File 'lib/nis/struct/message.rb', line 42

def to_s
  @value
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/nis/struct/message.rb', line 32

def valid?
  bytesize <= 512
end