Class: Gibbler::Digest
Overview
Gibbler::Digest
A tiny subclass of String which adds a few digest related convenience methods.
Instance Method Summary collapse
-
#==(ali) ⇒ Object
Returns true when
ali
matchesself
. -
#===(g) ⇒ Object
Returns true when
g
matches one of:self
,short
,shorter
,tiny
. - #base(base = Gibbler.default_base) ⇒ Object
- #base36 ⇒ Object
-
#short ⇒ Object
Returns the first 8 characters of itself (the digest).
-
#shorten(len = 20) ⇒ Object
Shorten the digest to the given (optional) length.
-
#shorter ⇒ Object
Returns the first 6 characters of itself (the digest).
-
#tiny ⇒ Object
Returns the first 4 characters of itself (the digest).
-
#to_i(base = nil) ⇒ Object
Return an integer assuming base is Gibbler.default_base.
-
#to_s(base = nil) ⇒ Object
Returns a string.
Methods inherited from String
Methods included from History
#commit, #find_long, #gibbler_commit, #gibbler_find_long, #gibbler_history, #gibbler_history?, #gibbler_object, #gibbler_revert!, #gibbler_stamp, #gibbler_valid?, #history, #history?, mutex, #object, #revert!, #stamp, #valid?
Methods included from String
Methods included from Object
#__gibbler, #digest_cache, #freeze, #gibbled?, #gibbler, #gibbler_debug, gibbler_fields, #gibbler_fields, included
Instance Method Details
#==(ali) ⇒ Object
Returns true when ali
matches self
"kimmy".gibbler == "c8027100ecc54945ab15ddac529230e38b1ba6a1" # => true
"kimmy".gibbler == "c8027100" # => false
112 113 114 115 |
# File 'lib/gibbler.rb', line 112 def ==(ali) return true if self.to_s == ali.to_s false end |
#===(g) ⇒ Object
Returns true when g
matches one of: self
, short
, shorter
, tiny
"kimmy".gibbler === "c8027100ecc54945ab15ddac529230e38b1ba6a1" # => true
"kimmy".gibbler === "c8027100" # => true
"kimmy".gibbler === "c80271" # => true
"kimmy".gibbler === "c802" # => true
124 125 126 127 |
# File 'lib/gibbler.rb', line 124 def ===(g) return true if [to_s, short, shorter, tiny].member?(g.to_s) false end |
#base(base = Gibbler.default_base) ⇒ Object
61 62 63 |
# File 'lib/gibbler.rb', line 61 def base(base=Gibbler.default_base) self.class.new(self.to_i(Gibbler.default_base).to_s(base)) end |
#base36 ⇒ Object
65 66 67 |
# File 'lib/gibbler.rb', line 65 def base36 base(36) end |
#short ⇒ Object
Returns the first 8 characters of itself (the digest).
e.g.
"kimmy".gibbler # => c8027100ecc54945ab15ddac529230e38b1ba6a1
"kimmy".gibbler.short # => c8027100
81 82 83 |
# File 'lib/gibbler.rb', line 81 def short shorten(8) end |
#shorten(len = 20) ⇒ Object
Shorten the digest to the given (optional) length.
70 71 72 |
# File 'lib/gibbler.rb', line 70 def shorten(len=20) self[0..len-1] end |
#shorter ⇒ Object
Returns the first 6 characters of itself (the digest).
e.g.
"kimmy".gibbler # => c8027100ecc54945ab15ddac529230e38b1ba6a1
"kimmy".gibbler.shorter # => c80271
92 93 94 |
# File 'lib/gibbler.rb', line 92 def shorter shorten(6) end |
#tiny ⇒ Object
Returns the first 4 characters of itself (the digest).
e.g.
"kimmy".gibbler # => c8027100ecc54945ab15ddac529230e38b1ba6a1
"kimmy".gibbler.tiny # => c802
103 104 105 |
# File 'lib/gibbler.rb', line 103 def tiny shorten(4) end |
#to_i(base = nil) ⇒ Object
Return an integer assuming base is Gibbler.default_base.
51 52 53 54 |
# File 'lib/gibbler.rb', line 51 def to_i(base=nil) base ||= Gibbler.default_base super(base) end |
#to_s(base = nil) ⇒ Object
Returns a string. Takes an optional base.
57 58 59 |
# File 'lib/gibbler.rb', line 57 def to_s(base=nil) base.nil? ? super() : super().to_i(Gibbler.default_base).to_s(base) end |