Class: Version::Tag

Inherits:
Object show all
Defined in:
lib/version.rb

Constant Summary collapse

@@tags =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, descr, rank, offset) ⇒ Tag

Returns a new instance of Tag.



215
216
217
# File 'lib/version.rb', line 215

def initialize ( name, descr, rank, offset )
  @name, @descr, @rank, @offset = name, descr, rank, offset
end

Instance Attribute Details

#descrObject

Returns the value of attribute descr.



213
214
215
# File 'lib/version.rb', line 213

def descr
  @descr
end

#nameObject

Returns the value of attribute name.



213
214
215
# File 'lib/version.rb', line 213

def name
  @name
end

#offsetObject

Returns the value of attribute offset.



213
214
215
# File 'lib/version.rb', line 213

def offset
  @offset
end

#rankObject

Returns the value of attribute rank.



213
214
215
# File 'lib/version.rb', line 213

def rank
  @rank
end

Class Method Details

.[](name, offset) ⇒ Object

Raises:

  • (ArgumentError)


231
232
233
234
235
# File 'lib/version.rb', line 231

def [] ( name, offset )
  f = @@tags[name]
  raise ArgumentError, "Unknown tag ``#{name}''" if f.nil?
  f[offset]
end

.tag(name, descr, rank) ⇒ Object



236
237
238
# File 'lib/version.rb', line 236

def tag ( name, descr, rank )
  @@tags[name] = lambda { |offset| Tag.new(name, descr, rank, offset) } 
end

Instance Method Details

#<=>(other) ⇒ Object



223
224
225
226
227
# File 'lib/version.rb', line 223

def <=> ( other )
  cmp = @rank <=> other.rank
  return cmp unless cmp.zero?
  @offset <=> other.offset
end

#pretty_stringObject



219
220
221
# File 'lib/version.rb', line 219

def pretty_string
  (offset.zero?)? descr : "#{descr} #{offset}"
end