shamazing 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -32,6 +32,10 @@ $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8 --integer
32
32
 
33
33
  $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8 -i
34
34
  20191041554
35
+
36
+ # Search through the shas using `git log --format="%H"` in the current directory.
37
+ $ shamazing -s
38
+ cddfaedaea
35
39
  ```
36
40
 
37
41
  ### Ruby Interface
@@ -46,6 +50,17 @@ Shamazing.string(sha)
46
50
 
47
51
  Shamazing.integer(sha)
48
52
  # => 20191041554
53
+
54
+ shas = %w(
55
+ fdb31214c2cca29e4f723ad676cddb043bd73986
56
+ 0c4b61fc2c5e7dd5566d42d0de1c431984899ddf
57
+ 9c2cddfaedaea9689a22e376aa20191041554fe8
58
+ f1b4c270f6746cbfff99bbf0f5a2388f4e509943
59
+ )
60
+ Shamazing.string_from_array(shas)
61
+ # => cddfaedaea
62
+ Shamazing.integer_from_array(shas)
63
+ # => 20191041554
49
64
  ```
50
65
 
51
66
  ## An Holman Project
data/bin/shamazing CHANGED
@@ -52,11 +52,25 @@ end
52
52
  parser.parse!
53
53
  sha = *ARGV
54
54
 
55
- if options[:string] && !options[:integer]
56
- puts Shamazing.string(sha)
57
- elsif options[:integer]
58
- puts Shamazing.integer(sha)
55
+ if !sha
56
+ # Automatically parse this repository's shas.
57
+ shas = `git log --format="%H"`.split("\n")
58
+
59
+ if options[:string] && !options[:integer]
60
+ puts Shamazing.string_from_array(shas)
61
+ elsif options[:integer]
62
+ puts Shamazing.integer_from_array(shas)
63
+ else
64
+ puts "Longest string: #{Shamazing.string_from_array(shas)}"
65
+ puts "Longest integer: #{Shamazing.integer_from_array(shas)}"
66
+ end
59
67
  else
60
- puts "Longest string: #{Shamazing.string(sha)}"
61
- puts "Longest integer: #{Shamazing.integer(sha)}"
68
+ if options[:string] && !options[:integer]
69
+ puts Shamazing.string(sha)
70
+ elsif options[:integer]
71
+ puts Shamazing.integer(sha)
72
+ else
73
+ puts "Longest string: #{Shamazing.string(sha)}"
74
+ puts "Longest integer: #{Shamazing.integer(sha)}"
75
+ end
62
76
  end
data/lib/shamazing.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  class Shamazing
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
 
4
- # Finds the longest continuous String in a sha.
4
+ # Finds the longest continuous String in a SHA.
5
+ #
6
+ # sha - The String SHA to analyze.
5
7
  #
6
8
  # Returns a String.
7
9
  def self.string(sha)
@@ -12,7 +14,21 @@ class Shamazing
12
14
  first
13
15
  end
14
16
 
15
- # Finds the longest continuous Integer in a sha.
17
+ # Finds the longest continuous String in an Array of SHAs.
18
+ #
19
+ # shas - The Array of SHAs to analyze.
20
+ #
21
+ # Returns the longest String.
22
+ def self.string_from_array(shas)
23
+ shas.
24
+ collect{|sha| string(sha)}.
25
+ sort{|a,b| b.length <=> a.length}.
26
+ first
27
+ end
28
+
29
+ # Finds the longest continuous Integer in a SHA.
30
+ #
31
+ # sha - The String SHA to analyze.
16
32
  #
17
33
  # Returns an Integer.
18
34
  def self.integer(sha)
@@ -21,4 +37,16 @@ class Shamazing
21
37
  sort{|a,b| b.length <=> a.length}.
22
38
  first.to_i
23
39
  end
40
+
41
+ # Finds the longest continuous Integer in an Array of SHAs.
42
+ #
43
+ # shas - The Array of SHAs to analyze.
44
+ #
45
+ # Returns the longest Integer.
46
+ def self.integer_from_array(shas)
47
+ shas.
48
+ collect{|sha| integer(sha).to_s}.
49
+ sort{|a,b| b.length <=> a.length}.
50
+ first.to_i
51
+ end
24
52
  end
data/shamazing.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'shamazing'
7
- s.version = '0.0.1'
7
+ s.version = '0.0.2'
8
8
  s.date = '2012-03-27'
9
9
  s.rubyforge_project = 'shamazing'
10
10
 
@@ -4,6 +4,12 @@ require 'lib/shamazing'
4
4
  class TestShamazing < Test::Unit::TestCase
5
5
  def setup
6
6
  @sha = '9c2cddfaedaea9689a22e376aa20191041554fe8'
7
+ @shas = %w(
8
+ fdb31214c2cca29e4f723ad676cddb043bd73986
9
+ 0c4b61fc2c5e7dd5566d42d0de1c431984899ddf
10
+ 9c2cddfaedaea9689a22e376aa20191041554fe8
11
+ f1b4c270f6746cbfff99bbf0f5a2388f4e509943
12
+ )
7
13
  end
8
14
 
9
15
  def test_string
@@ -14,10 +20,18 @@ class TestShamazing < Test::Unit::TestCase
14
20
  assert_equal 'cddfaedaea', Shamazing.string(@sha.upcase)
15
21
  end
16
22
 
23
+ def test_string_from_array
24
+ assert_equal 'cddfaedaea', Shamazing.string_from_array(@shas)
25
+ end
26
+
17
27
  def test_integer
18
28
  assert_equal 20191041554, Shamazing.integer(@sha)
19
29
  end
20
30
 
31
+ def test_integer_from_array
32
+ assert_equal 20191041554, Shamazing.integer_from_array(@shas)
33
+ end
34
+
21
35
  def test_cli
22
36
  output = `bin/shamazing #{@sha}`.chomp
23
37
 
@@ -34,4 +48,9 @@ class TestShamazing < Test::Unit::TestCase
34
48
  assert_equal '20191041554', `bin/shamazing #{@sha} -i`.chomp
35
49
  assert_equal '20191041554', `bin/shamazing #{@sha} --integer`.chomp
36
50
  end
51
+
52
+ def test_cli_git
53
+ assert_match /Longest string: /, `bin/shamazing`.chomp
54
+ assert_match /Longest integer: /, `bin/shamazing`.chomp
55
+ end
37
56
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shamazing
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Zach Holman