Class: IPAddress::Rle

Inherits:
Object
  • Object
show all
Defined in:
lib/ipaddress/rle.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ Rle

Returns a new instance of Rle.



52
53
54
55
56
57
# File 'lib/ipaddress/rle.rb', line 52

def initialize(obj)
  @part = obj[:part]
  @pos = obj[:pos]
  @cnt = obj[:cnt]
  @max = obj[:max]
end

Instance Attribute Details

#cntObject

Returns the value of attribute cnt.



50
51
52
# File 'lib/ipaddress/rle.rb', line 50

def cnt
  @cnt
end

#maxObject

Returns the value of attribute max.



50
51
52
# File 'lib/ipaddress/rle.rb', line 50

def max
  @max
end

#partObject

Returns the value of attribute part.



50
51
52
# File 'lib/ipaddress/rle.rb', line 50

def part
  @part
end

#posObject

Returns the value of attribute pos.



50
51
52
# File 'lib/ipaddress/rle.rb', line 50

def pos
  @pos
end

Class Method Details

.code(parts) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ipaddress/rle.rb', line 72

def self.code(parts)
  last = Last.new()
  # println!("code")
  parts.length.times do |i|
    part = parts[i]
    # console.log(`part:${part}`)
    if (last.val && last.val.part == part)
      last.val.cnt += 1
    else
      last.handle_last()
      last.val = Rle.new({ part: part, pos: 0, cnt: 1, max: true })
    end
  end

  last.handle_last()
  return last.ret
end

Instance Method Details

#eq(other) ⇒ Object



63
64
65
66
# File 'lib/ipaddress/rle.rb', line 63

def eq(other)
  return @part == other.part && @pos == other.pos &&
    @cnt == other.cnt && @max == other.max
end

#ne(other) ⇒ Object



68
69
70
# File 'lib/ipaddress/rle.rb', line 68

def ne(other)
  return !eq(other)
end

#toStringObject



59
60
61
# File 'lib/ipaddress/rle.rb', line 59

def toString()
  return "<Rle@part:#{@part},pos:#{@pos},cnt:#{@cnt},max:#{@max}>"
end