Class: Shamazing

Inherits:
Object
  • Object
show all
Defined in:
lib/shamazing.rb

Constant Summary collapse

VERSION =
'0.0.5'

Class Method Summary collapse

Class Method Details

.integer(sha) ⇒ Object

Finds the longest continuous Integer in a SHA.

sha - The String SHA to analyze.

Returns an Integer.



36
37
38
39
40
41
# File 'lib/shamazing.rb', line 36

def self.integer(sha)
  sha.
    scan(/[0-9]+/).
    sort{|a,b| b.length <=> a.length}.
    first.to_i
end

.integer_from_array(shas, full = false) ⇒ Object

Finds the longest continuous Integer in an Array of SHAs.

shas - The Array of SHAs to analyze. full - A Boolean: should we return the full SHA instead of the snippet?

Returns the longest Integer.



49
50
51
52
53
54
55
# File 'lib/shamazing.rb', line 49

def self.integer_from_array(shas,full=false)
  longest = shas.
    collect{|sha| integer(sha).to_s}.
    sort{|a,b| b.length <=> a.length}.
    first.to_i
  full ? shas.find{|sha| sha.match(/#{longest}/)} : longest
end

.string(sha) ⇒ Object

Finds the longest continuous String in a SHA.

sha - The String SHA to analyze.

Returns a String.



9
10
11
12
13
14
15
# File 'lib/shamazing.rb', line 9

def self.string(sha)
  sha.
    downcase.
    scan(/[a-f]+/).
    sort{|a,b| b.length <=> a.length}.
    first
end

.string_from_array(shas, full = false) ⇒ Object

Finds the longest continuous String in an Array of SHAs.

shas - The Array of SHAs to analyze. full - A Boolean: should we return the full SHA instead of the snippet?

Returns the longest String.



23
24
25
26
27
28
29
# File 'lib/shamazing.rb', line 23

def self.string_from_array(shas,full=false)
  longest = shas.
    collect{|sha| string(sha)}.
    sort{|a,b| b.length <=> a.length}.
    first
  full ? shas.find{|sha| sha.match(/#{longest}/)} : longest
end