Class: JadePair

Inherits:
Object
  • Object
show all
Defined in:
jade/jade_pair.rb

Overview

The JadePair is essential to the JadeObject. It stores two stings of first and second. Commonly the first is the variable name and the second is the variable data. JadePairs are used commonly throughout both the JadeSerializer and JadeDeserializer too.

Author:

  • Joseph Beck

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first = nil, second = nil) ⇒ NilClass

Initializes the instance of both first and second. These default to nil if nothing is provided in the parameters.

Parameters:

  • (String, String)


26
27
28
29
# File 'jade/jade_pair.rb', line 26

def initialize(first = nil, second = nil)
  @first = first
  @second = second
end

Instance Attribute Details

#:first, :second(: first, : second) ⇒ Object

First and second are commonly used outside of the JadePair itself and therefore require an attribute accessor.



18
# File 'jade/jade_pair.rb', line 18

attr_accessor :first, :second

#firstObject

First and second are commonly used outside of the JadePair itself and therefore require an attribute accessor.



18
19
20
# File 'jade/jade_pair.rb', line 18

def first
  @first
end

#secondObject

First and second are commonly used outside of the JadePair itself and therefore require an attribute accessor.



18
19
20
# File 'jade/jade_pair.rb', line 18

def second
  @second
end

Instance Method Details

#empty?Boolean

Checks whether the current instance of JadePair is empty Useful for preventing uses of nil JadePairs

Parameters:

  • (NilClass)

Returns:

  • (Boolean)


88
89
90
# File 'jade/jade_pair.rb', line 88

def empty?
  @first.nil? && @second.nil?
end

#eql?(other) ⇒ Boolean

Checks whether the current instance of JadePair is equal to another JadePair Useful for checking JadePair equivalence

Parameters:

Returns:

  • (Boolean)


98
99
100
101
# File 'jade/jade_pair.rb', line 98

def eql?(other)
  ((@first.eql? other.first) &&
   (@second.eql? other.second))
end

#replace(first, second) ⇒ NilClass

Allows both the values of first and second to be replaced.

Parameters:

  • (String, String)

Returns:

  • (NilClass)


36
37
38
39
40
# File 'jade/jade_pair.rb', line 36

def replace(first, second)
  @first = first
  @second = second
  nil
end

#replace_first(first) ⇒ NilClass

Allows the value of first to be replaced.

Parameters:

  • (String)

Returns:

  • (NilClass)


47
48
49
50
# File 'jade/jade_pair.rb', line 47

def replace_first(first)
  @first = first
  nil
end

#replace_second(second) ⇒ NilClass

Allows the value of second to be replaced.

Parameters:

  • (String)

Returns:

  • (NilClass)


57
58
59
60
# File 'jade/jade_pair.rb', line 57

def replace_second(second)
  @second = second
  nil
end

#to_arrayString[]

to_array provides an array of both the values of first and second. This may be useful in some cases of JadeObject construction.

Parameters:

  • (NilClass)

Returns:

  • (String[])


68
69
70
# File 'jade/jade_pair.rb', line 68

def to_array
  [@first, @second]
end

#to_strString

to_str converts the current instance of the JadePair to a string. Useful when wanting a simple representation of the current JadePair.

Parameters:

  • (NilClass)

Returns:

  • (String)


78
79
80
# File 'jade/jade_pair.rb', line 78

def to_str
  "#{@first} : #{@second}"
end