tins 0.3.14 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,4 +4,4 @@ source :rubygems
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'simplecov', '0.5.4', :platform => :mri_19
7
+ gem 'simplecov', '0.6.2', :platform => :mri_19
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.14
1
+ 0.4.0
@@ -1,5 +1,19 @@
1
1
  module Tins
2
2
  module GO
3
+ module EnumerableExtension
4
+ def push(argument)
5
+ @arguments ||= []
6
+ @arguments.push argument
7
+ self
8
+ end
9
+
10
+ def each(&block)
11
+ @arguments.each(&block)
12
+ self
13
+ end
14
+ include Enumerable
15
+ end
16
+
3
17
  module_function
4
18
 
5
19
  # Parses the argument array _args_, according to the pattern _s_, to
@@ -10,7 +24,7 @@ module Tins
10
24
  # An option hash is returned with all found options set to true or the
11
25
  # found option argument.
12
26
  def go(s, args = ARGV)
13
- b,v = s.scan(/(.)(:?)/).inject([{},{}]) { |t,(o,a)|
27
+ b, v = s.scan(/(.)(:?)/).inject([ {}, {} ]) { |t, (o, a)|
14
28
  a = a == ':'
15
29
  t[a ? 1 : 0][o] = a ? nil : false
16
30
  t
@@ -22,13 +36,24 @@ module Tins
22
36
  o = p.slice!(0, 1)
23
37
  if v.key?(o)
24
38
  if p == '' then
25
- v[o] = args.shift or break 1
39
+ a = args.shift or break 1
26
40
  else
27
- v[0] = p
41
+ a = p
42
+ end
43
+ if v[o].nil?
44
+ a.extend EnumerableExtension
45
+ a.push a
46
+ v[o] = a
47
+ else
48
+ v[o].push a
28
49
  end
29
50
  break
30
51
  elsif b.key?(o)
31
- b[o] = true
52
+ if b[o] == false
53
+ b[o]= 1
54
+ else
55
+ b[o] += 1
56
+ end
32
57
  else
33
58
  args.unshift a
34
59
  break 1
@@ -1,6 +1,6 @@
1
1
  module Tins
2
2
  # Tins version
3
- VERSION = '0.3.14'
3
+ VERSION = '0.4.0'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
  require 'tins/xt'
3
3
 
4
4
  module Tins
5
- class AskAndSendTest
5
+ class AskAndSendTest < Test::Unit::TestCase
6
6
  class A
7
7
  public
8
8
 
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+ require 'tins/go'
3
+
4
+ module Tins
5
+ class GoTest < Test::Unit::TestCase
6
+ include Tins::GO
7
+
8
+
9
+ def test_empty_string
10
+ r = go '', %w[a b c]
11
+ assert_equal({}, r)
12
+ end
13
+
14
+ def test_empty_args
15
+ r = go 'ab:', []
16
+ assert_equal({ 'a' => false, 'b' => nil }, r)
17
+ end
18
+
19
+ def test_simple
20
+ r = go 'ab:', %w[-b hello -a -c]
21
+ assert_equal({ 'a' => 1, 'b' => 'hello' }, r)
22
+ end
23
+
24
+ def test_complex
25
+ r = go 'ab:', %w[-a -b hello -a -bworld -c]
26
+ assert_equal({ 'a' => 2, 'b' => 'hello' }, r)
27
+ assert_equal %w[hello world], r['b'].to_a
28
+ end
29
+
30
+ def test_complex2
31
+ r = go 'ab:', %w[-b hello -aa -b world -c]
32
+ assert_equal({ 'a' => 2, 'b' => 'hello' }, r)
33
+ assert_equal %w[hello world], r['b'].to_a
34
+ end
35
+ end
36
+ end
@@ -2,21 +2,21 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "tins"
5
- s.version = "0.3.14"
5
+ s.version = "0.4.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Florian Frank"]
9
- s.date = "2012-04-27"
9
+ s.date = "2012-04-29"
10
10
  s.description = "All the stuff that isn't good/big enough for a real library."
11
11
  s.email = "flori@ping.de"
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/spruz.rb", "lib/tins/hash_symbolize_keys_recursive.rb", "lib/tins/ask_and_send.rb", "lib/tins/string_underscore.rb", "lib/tins/hash_union.rb", "lib/tins/write.rb", "lib/tins/version.rb", "lib/tins/extract_last_argument_options.rb", "lib/tins/alias.rb", "lib/tins/round.rb", "lib/tins/date_dummy.rb", "lib/tins/go.rb", "lib/tins/find.rb", "lib/tins/generator.rb", "lib/tins/string_camelize.rb", "lib/tins/shuffle.rb", "lib/tins/deep_dup.rb", "lib/tins/memoize.rb", "lib/tins/lines_file.rb", "lib/tins/subhash.rb", "lib/tins/bijection.rb", "lib/tins/limited.rb", "lib/tins/attempt.rb", "lib/tins/to_proc.rb", "lib/tins/module_group.rb", "lib/tins/null.rb", "lib/tins/require_maybe.rb", "lib/tins/secure_write.rb", "lib/tins/xt.rb", "lib/tins/file_binary.rb", "lib/tins/string_version.rb", "lib/tins/once.rb", "lib/tins/xt/named.rb", "lib/tins/xt/hash_symbolize_keys_recursive.rb", "lib/tins/xt/ask_and_send.rb", "lib/tins/xt/string_underscore.rb", "lib/tins/xt/hash_union.rb", "lib/tins/xt/write.rb", "lib/tins/xt/extract_last_argument_options.rb", "lib/tins/xt/irb.rb", "lib/tins/xt/round.rb", "lib/tins/xt/date_dummy.rb", "lib/tins/xt/string_camelize.rb", "lib/tins/xt/shuffle.rb", "lib/tins/xt/deep_dup.rb", "lib/tins/xt/symbol_to_proc.rb", "lib/tins/xt/subhash.rb", "lib/tins/xt/attempt.rb", "lib/tins/xt/null.rb", "lib/tins/xt/require_maybe.rb", "lib/tins/xt/secure_write.rb", "lib/tins/xt/file_binary.rb", "lib/tins/xt/string_version.rb", "lib/tins/xt/p.rb", "lib/tins/xt/partial_application.rb", "lib/tins/xt/time_dummy.rb", "lib/tins/xt/string.rb", "lib/tins/xt/full.rb", "lib/tins/xt/range_plus.rb", "lib/tins/xt/count_by.rb", "lib/tins/xt/blank.rb", "lib/tins/xt/uniq_by.rb", "lib/tins/xt/if_predicate.rb", "lib/tins/xt/date_time_dummy.rb", "lib/tins/p.rb", "lib/tins/minimize.rb", "lib/tins/partial_application.rb", "lib/tins/time_dummy.rb", "lib/tins/range_plus.rb", "lib/tins/count_by.rb", "lib/tins/uniq_by.rb", "lib/tins/if_predicate.rb", "lib/tins/date_time_dummy.rb", "lib/tins.rb"]
13
- s.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE", "README.rdoc", "Rakefile", "TODO", "VERSION", "lib/spruz", "lib/spruz.rb", "lib/tins.rb", "lib/tins/alias.rb", "lib/tins/ask_and_send.rb", "lib/tins/attempt.rb", "lib/tins/bijection.rb", "lib/tins/count_by.rb", "lib/tins/date_dummy.rb", "lib/tins/date_time_dummy.rb", "lib/tins/deep_dup.rb", "lib/tins/extract_last_argument_options.rb", "lib/tins/file_binary.rb", "lib/tins/find.rb", "lib/tins/generator.rb", "lib/tins/go.rb", "lib/tins/hash_symbolize_keys_recursive.rb", "lib/tins/hash_union.rb", "lib/tins/if_predicate.rb", "lib/tins/limited.rb", "lib/tins/lines_file.rb", "lib/tins/memoize.rb", "lib/tins/minimize.rb", "lib/tins/module_group.rb", "lib/tins/null.rb", "lib/tins/once.rb", "lib/tins/p.rb", "lib/tins/partial_application.rb", "lib/tins/range_plus.rb", "lib/tins/require_maybe.rb", "lib/tins/round.rb", "lib/tins/secure_write.rb", "lib/tins/shuffle.rb", "lib/tins/string_camelize.rb", "lib/tins/string_underscore.rb", "lib/tins/string_version.rb", "lib/tins/subhash.rb", "lib/tins/time_dummy.rb", "lib/tins/to_proc.rb", "lib/tins/uniq_by.rb", "lib/tins/version.rb", "lib/tins/write.rb", "lib/tins/xt.rb", "lib/tins/xt/ask_and_send.rb", "lib/tins/xt/attempt.rb", "lib/tins/xt/blank.rb", "lib/tins/xt/count_by.rb", "lib/tins/xt/date_dummy.rb", "lib/tins/xt/date_time_dummy.rb", "lib/tins/xt/deep_dup.rb", "lib/tins/xt/extract_last_argument_options.rb", "lib/tins/xt/file_binary.rb", "lib/tins/xt/full.rb", "lib/tins/xt/hash_symbolize_keys_recursive.rb", "lib/tins/xt/hash_union.rb", "lib/tins/xt/if_predicate.rb", "lib/tins/xt/irb.rb", "lib/tins/xt/named.rb", "lib/tins/xt/null.rb", "lib/tins/xt/p.rb", "lib/tins/xt/partial_application.rb", "lib/tins/xt/range_plus.rb", "lib/tins/xt/require_maybe.rb", "lib/tins/xt/round.rb", "lib/tins/xt/secure_write.rb", "lib/tins/xt/shuffle.rb", "lib/tins/xt/string.rb", "lib/tins/xt/string_camelize.rb", "lib/tins/xt/string_underscore.rb", "lib/tins/xt/string_version.rb", "lib/tins/xt/subhash.rb", "lib/tins/xt/symbol_to_proc.rb", "lib/tins/xt/time_dummy.rb", "lib/tins/xt/uniq_by.rb", "lib/tins/xt/write.rb", "tests/ask_and_send_test.rb", "tests/bijection_test.rb", "tests/blank_full_test.rb", "tests/count_by_test.rb", "tests/date_dummy_test.rb", "tests/date_time_dummy_test.rb", "tests/deep_dup_test.rb", "tests/extract_last_argument_options_test.rb", "tests/file_binary_test.rb", "tests/find_test.rb", "tests/generator_test.rb", "tests/hash_symbolize_keys_recursive_test.rb", "tests/hash_union_test.rb", "tests/if_predicate_test.rb", "tests/limited_test.rb", "tests/lines_file_test.rb", "tests/memoize_test.rb", "tests/minimize_test.rb", "tests/module_group_test.rb", "tests/named_test.rb", "tests/null_test.rb", "tests/partial_application_test.rb", "tests/range_plus_test.rb", "tests/require_maybe_test.rb", "tests/round_test.rb", "tests/secure_write_test.rb", "tests/shuffle_test.rb", "tests/string_camelize_test.rb", "tests/string_underscore_test.rb", "tests/string_version_test.rb", "tests/subhash_test.rb", "tests/test_helper.rb", "tests/time_dummy_test.rb", "tests/try_test.rb", "tests/uniq_by_test.rb", "tins.gemspec"]
13
+ s.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE", "README.rdoc", "Rakefile", "TODO", "VERSION", "lib/spruz", "lib/spruz.rb", "lib/tins.rb", "lib/tins/alias.rb", "lib/tins/ask_and_send.rb", "lib/tins/attempt.rb", "lib/tins/bijection.rb", "lib/tins/count_by.rb", "lib/tins/date_dummy.rb", "lib/tins/date_time_dummy.rb", "lib/tins/deep_dup.rb", "lib/tins/extract_last_argument_options.rb", "lib/tins/file_binary.rb", "lib/tins/find.rb", "lib/tins/generator.rb", "lib/tins/go.rb", "lib/tins/hash_symbolize_keys_recursive.rb", "lib/tins/hash_union.rb", "lib/tins/if_predicate.rb", "lib/tins/limited.rb", "lib/tins/lines_file.rb", "lib/tins/memoize.rb", "lib/tins/minimize.rb", "lib/tins/module_group.rb", "lib/tins/null.rb", "lib/tins/once.rb", "lib/tins/p.rb", "lib/tins/partial_application.rb", "lib/tins/range_plus.rb", "lib/tins/require_maybe.rb", "lib/tins/round.rb", "lib/tins/secure_write.rb", "lib/tins/shuffle.rb", "lib/tins/string_camelize.rb", "lib/tins/string_underscore.rb", "lib/tins/string_version.rb", "lib/tins/subhash.rb", "lib/tins/time_dummy.rb", "lib/tins/to_proc.rb", "lib/tins/uniq_by.rb", "lib/tins/version.rb", "lib/tins/write.rb", "lib/tins/xt.rb", "lib/tins/xt/ask_and_send.rb", "lib/tins/xt/attempt.rb", "lib/tins/xt/blank.rb", "lib/tins/xt/count_by.rb", "lib/tins/xt/date_dummy.rb", "lib/tins/xt/date_time_dummy.rb", "lib/tins/xt/deep_dup.rb", "lib/tins/xt/extract_last_argument_options.rb", "lib/tins/xt/file_binary.rb", "lib/tins/xt/full.rb", "lib/tins/xt/hash_symbolize_keys_recursive.rb", "lib/tins/xt/hash_union.rb", "lib/tins/xt/if_predicate.rb", "lib/tins/xt/irb.rb", "lib/tins/xt/named.rb", "lib/tins/xt/null.rb", "lib/tins/xt/p.rb", "lib/tins/xt/partial_application.rb", "lib/tins/xt/range_plus.rb", "lib/tins/xt/require_maybe.rb", "lib/tins/xt/round.rb", "lib/tins/xt/secure_write.rb", "lib/tins/xt/shuffle.rb", "lib/tins/xt/string.rb", "lib/tins/xt/string_camelize.rb", "lib/tins/xt/string_underscore.rb", "lib/tins/xt/string_version.rb", "lib/tins/xt/subhash.rb", "lib/tins/xt/symbol_to_proc.rb", "lib/tins/xt/time_dummy.rb", "lib/tins/xt/uniq_by.rb", "lib/tins/xt/write.rb", "tests/ask_and_send_test.rb", "tests/bijection_test.rb", "tests/blank_full_test.rb", "tests/count_by_test.rb", "tests/date_dummy_test.rb", "tests/date_time_dummy_test.rb", "tests/deep_dup_test.rb", "tests/extract_last_argument_options_test.rb", "tests/file_binary_test.rb", "tests/find_test.rb", "tests/generator_test.rb", "tests/go_test.rb", "tests/hash_symbolize_keys_recursive_test.rb", "tests/hash_union_test.rb", "tests/if_predicate_test.rb", "tests/limited_test.rb", "tests/lines_file_test.rb", "tests/memoize_test.rb", "tests/minimize_test.rb", "tests/module_group_test.rb", "tests/named_test.rb", "tests/null_test.rb", "tests/partial_application_test.rb", "tests/range_plus_test.rb", "tests/require_maybe_test.rb", "tests/round_test.rb", "tests/secure_write_test.rb", "tests/shuffle_test.rb", "tests/string_camelize_test.rb", "tests/string_underscore_test.rb", "tests/string_version_test.rb", "tests/subhash_test.rb", "tests/test_helper.rb", "tests/time_dummy_test.rb", "tests/try_test.rb", "tests/uniq_by_test.rb", "tins.gemspec"]
14
14
  s.homepage = "http://flori.github.com/tins"
15
15
  s.rdoc_options = ["--title", "Tins - Useful stuff.", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubygems_version = "1.8.23"
18
18
  s.summary = "Useful stuff."
19
- s.test_files = ["tests/generator_test.rb", "tests/null_test.rb", "tests/find_test.rb", "tests/date_time_dummy_test.rb", "tests/range_plus_test.rb", "tests/deep_dup_test.rb", "tests/bijection_test.rb", "tests/memoize_test.rb", "tests/limited_test.rb", "tests/count_by_test.rb", "tests/blank_full_test.rb", "tests/file_binary_test.rb", "tests/if_predicate_test.rb", "tests/secure_write_test.rb", "tests/string_version_test.rb", "tests/try_test.rb", "tests/extract_last_argument_options_test.rb", "tests/require_maybe_test.rb", "tests/uniq_by_test.rb", "tests/time_dummy_test.rb", "tests/string_camelize_test.rb", "tests/lines_file_test.rb", "tests/string_underscore_test.rb", "tests/date_dummy_test.rb", "tests/hash_symbolize_keys_recursive_test.rb", "tests/named_test.rb", "tests/hash_union_test.rb", "tests/subhash_test.rb", "tests/partial_application_test.rb", "tests/minimize_test.rb", "tests/round_test.rb", "tests/test_helper.rb", "tests/shuffle_test.rb", "tests/ask_and_send_test.rb", "tests/module_group_test.rb", "tests/generator_test.rb", "tests/null_test.rb", "tests/find_test.rb", "tests/date_time_dummy_test.rb", "tests/range_plus_test.rb", "tests/deep_dup_test.rb", "tests/bijection_test.rb", "tests/memoize_test.rb", "tests/limited_test.rb", "tests/count_by_test.rb", "tests/blank_full_test.rb", "tests/file_binary_test.rb", "tests/if_predicate_test.rb", "tests/secure_write_test.rb", "tests/string_version_test.rb", "tests/try_test.rb", "tests/extract_last_argument_options_test.rb", "tests/require_maybe_test.rb", "tests/uniq_by_test.rb", "tests/time_dummy_test.rb", "tests/string_camelize_test.rb", "tests/lines_file_test.rb", "tests/string_underscore_test.rb", "tests/date_dummy_test.rb", "tests/hash_symbolize_keys_recursive_test.rb", "tests/named_test.rb", "tests/hash_union_test.rb", "tests/subhash_test.rb", "tests/partial_application_test.rb", "tests/minimize_test.rb", "tests/round_test.rb", "tests/shuffle_test.rb", "tests/ask_and_send_test.rb", "tests/module_group_test.rb"]
19
+ s.test_files = ["tests/generator_test.rb", "tests/null_test.rb", "tests/find_test.rb", "tests/date_time_dummy_test.rb", "tests/range_plus_test.rb", "tests/deep_dup_test.rb", "tests/bijection_test.rb", "tests/memoize_test.rb", "tests/limited_test.rb", "tests/count_by_test.rb", "tests/blank_full_test.rb", "tests/file_binary_test.rb", "tests/if_predicate_test.rb", "tests/secure_write_test.rb", "tests/string_version_test.rb", "tests/try_test.rb", "tests/extract_last_argument_options_test.rb", "tests/require_maybe_test.rb", "tests/uniq_by_test.rb", "tests/time_dummy_test.rb", "tests/string_camelize_test.rb", "tests/lines_file_test.rb", "tests/string_underscore_test.rb", "tests/date_dummy_test.rb", "tests/hash_symbolize_keys_recursive_test.rb", "tests/named_test.rb", "tests/hash_union_test.rb", "tests/go_test.rb", "tests/subhash_test.rb", "tests/partial_application_test.rb", "tests/minimize_test.rb", "tests/round_test.rb", "tests/test_helper.rb", "tests/shuffle_test.rb", "tests/ask_and_send_test.rb", "tests/module_group_test.rb", "tests/generator_test.rb", "tests/null_test.rb", "tests/find_test.rb", "tests/date_time_dummy_test.rb", "tests/range_plus_test.rb", "tests/deep_dup_test.rb", "tests/bijection_test.rb", "tests/memoize_test.rb", "tests/limited_test.rb", "tests/count_by_test.rb", "tests/blank_full_test.rb", "tests/file_binary_test.rb", "tests/if_predicate_test.rb", "tests/secure_write_test.rb", "tests/string_version_test.rb", "tests/try_test.rb", "tests/extract_last_argument_options_test.rb", "tests/require_maybe_test.rb", "tests/uniq_by_test.rb", "tests/time_dummy_test.rb", "tests/string_camelize_test.rb", "tests/lines_file_test.rb", "tests/string_underscore_test.rb", "tests/date_dummy_test.rb", "tests/hash_symbolize_keys_recursive_test.rb", "tests/named_test.rb", "tests/hash_union_test.rb", "tests/go_test.rb", "tests/subhash_test.rb", "tests/partial_application_test.rb", "tests/minimize_test.rb", "tests/round_test.rb", "tests/shuffle_test.rb", "tests/ask_and_send_test.rb", "tests/module_group_test.rb"]
20
20
 
21
21
  if s.respond_to? :specification_version then
22
22
  s.specification_version = 3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-27 00:00:00.000000000 Z
12
+ date: 2012-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gem_hadar
@@ -307,6 +307,7 @@ files:
307
307
  - tests/file_binary_test.rb
308
308
  - tests/find_test.rb
309
309
  - tests/generator_test.rb
310
+ - tests/go_test.rb
310
311
  - tests/hash_symbolize_keys_recursive_test.rb
311
312
  - tests/hash_union_test.rb
312
313
  - tests/if_predicate_test.rb
@@ -350,7 +351,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
350
351
  version: '0'
351
352
  segments:
352
353
  - 0
353
- hash: -1430229062218128228
354
+ hash: -1325111411765569981
354
355
  required_rubygems_version: !ruby/object:Gem::Requirement
355
356
  none: false
356
357
  requirements:
@@ -418,6 +419,8 @@ test_files:
418
419
  dGVzdHMvbmFtZWRfdGVzdC5yYg==
419
420
  - !binary |-
420
421
  dGVzdHMvaGFzaF91bmlvbl90ZXN0LnJi
422
+ - !binary |-
423
+ dGVzdHMvZ29fdGVzdC5yYg==
421
424
  - !binary |-
422
425
  dGVzdHMvc3ViaGFzaF90ZXN0LnJi
423
426
  - !binary |-