Class: Commons::Lang::Time::DurationFormatUtils::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/commons/lang/time/duration_format_utils.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, count = 1) ⇒ Token

Returns a new instance of Token.



221
222
223
224
225
226
# File 'lib/commons/lang/time/duration_format_utils.rb', line 221

def initialize(value, count = 1)
  super()
  
  @value = value
  @count = count
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



209
210
211
# File 'lib/commons/lang/time/duration_format_utils.rb', line 209

def count
  @count
end

#valueObject (readonly)

Returns the value of attribute value.



209
210
211
# File 'lib/commons/lang/time/duration_format_utils.rb', line 209

def value
  @value
end

Class Method Details

.contains_token_with_value?(tokens, value) ⇒ Boolean

Returns:

  • (Boolean)


211
212
213
214
215
216
217
218
# File 'lib/commons/lang/time/duration_format_utils.rb', line 211

def self.contains_token_with_value?(tokens, value)
  tokens.each {|token|
    if token.value.equal?(value)
      return true
    end
  }
  return false
end

Instance Method Details

#==(other) ⇒ Object



234
235
236
# File 'lib/commons/lang/time/duration_format_utils.rb', line 234

def ==(other)
  return self.eql?(other)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/commons/lang/time/duration_format_utils.rb', line 239

def eql?(other)
  if other.kind_of?(Token)
    if !@value.class.equal?(other.value.class)
      return false
    end
    if @count != other.count
      return false
    end
    if @value.kind_of?(String)
      return @value.to_s == other.value.to_s
    elsif @value.kind_of?(Numeric)
      return @value == other.value
    else
      return @value.equal?(other.value)
    end
  end
  
  return false
end

#hashObject



260
261
262
# File 'lib/commons/lang/time/duration_format_utils.rb', line 260

def hash
  return @value.hash
end

#incrementObject



229
230
231
# File 'lib/commons/lang/time/duration_format_utils.rb', line 229

def increment
  @count += 1
end

#to_sObject



265
266
267
# File 'lib/commons/lang/time/duration_format_utils.rb', line 265

def to_s
  return @value.to_s * @count
end

#to_strObject



270
271
272
# File 'lib/commons/lang/time/duration_format_utils.rb', line 270

def to_str
  return self.to_s
end