Module: Gibbler::Digest::InstanceMethods
- Included in:
- Gibbler::Digest
- Defined in:
- lib/gibbler.rb
Instance Method Summary collapse
-
#==(ali) ⇒ Object
Returns true when
alimatchesself. -
#===(g) ⇒ Object
Returns true when
gmatches 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
101 102 103 104 |
# File 'lib/gibbler.rb', line 101 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
113 114 115 116 |
# File 'lib/gibbler.rb', line 113 def ===(g) return true if [to_s, short, shorter, tiny].member?(g.to_s) false end |
#base(base = Gibbler.default_base) ⇒ Object
48 49 50 51 52 |
# File 'lib/gibbler.rb', line 48 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
54 55 56 |
# File 'lib/gibbler.rb', line 54 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
70 71 72 |
# File 'lib/gibbler.rb', line 70 def short shorten(8) end |
#shorten(len = 20) ⇒ Object
Shorten the digest to the given (optional) length.
59 60 61 |
# File 'lib/gibbler.rb', line 59 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
81 82 83 |
# File 'lib/gibbler.rb', line 81 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
92 93 94 |
# File 'lib/gibbler.rb', line 92 def tiny shorten(4) end |
#to_i(base = nil) ⇒ Object
Return an integer assuming base is Gibbler.default_base.
38 39 40 41 |
# File 'lib/gibbler.rb', line 38 def to_i(base=nil) base ||= Gibbler.default_base super(base) end |
#to_s(base = nil) ⇒ Object
Returns a string. Takes an optional base.
44 45 46 |
# File 'lib/gibbler.rb', line 44 def to_s(base=nil) base.nil? ? super() : super().to_i(Gibbler.default_base).to_s(base) end |