Module: Gibbler::Digest::InstanceMethods
- Included in:
- Gibbler, Gibbler::Digest
- Defined in:
- lib/gibbler.rb
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.
Instance Method Details
#==(ali) ⇒ Object
Returns true when ali
matches self
"kimmy".gibbler == "c8027100ecc54945ab15ddac529230e38b1ba6a1" # => true
"kimmy".gibbler == "c8027100" # => false
113 114 115 116 |
# File 'lib/gibbler.rb', line 113 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
125 126 127 128 |
# File 'lib/gibbler.rb', line 125 def ===(g) return true if [to_s, short, shorter, tiny].member?(g.to_s) false end |
#base(base = Gibbler.default_base) ⇒ Object
60 61 62 63 64 |
# File 'lib/gibbler.rb', line 60 def base(base=Gibbler.default_base) v = self.to_i(Gibbler.default_base).to_s(base) v.extend Gibbler::Digest::InstanceMethods self.class.new v end |
#base36 ⇒ Object
66 67 68 |
# File 'lib/gibbler.rb', line 66 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
82 83 84 |
# File 'lib/gibbler.rb', line 82 def short shorten(8) end |
#shorten(len = 20) ⇒ Object
Shorten the digest to the given (optional) length.
71 72 73 |
# File 'lib/gibbler.rb', line 71 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
93 94 95 |
# File 'lib/gibbler.rb', line 93 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
104 105 106 |
# File 'lib/gibbler.rb', line 104 def tiny shorten(4) end |
#to_i(base = nil) ⇒ Object
Return an integer assuming base is Gibbler.default_base.
50 51 52 53 |
# File 'lib/gibbler.rb', line 50 def to_i(base=nil) base ||= Gibbler.default_base super(base) end |
#to_s(base = nil) ⇒ Object
Returns a string. Takes an optional base.
56 57 58 |
# File 'lib/gibbler.rb', line 56 def to_s(base=nil) base.nil? ? super() : super().to_i(Gibbler.default_base).to_s(base) end |