tins 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -1
  3. data/Gemfile +2 -0
  4. data/README.md +25 -0
  5. data/Rakefile +1 -1
  6. data/VERSION +1 -1
  7. data/examples/bb3.stm +15 -15
  8. data/examples/concatenate_compare.mtm +26 -26
  9. data/examples/length_difference.mtm +12 -12
  10. data/examples/let.rb +2 -2
  11. data/examples/ones_difference.mtm +7 -7
  12. data/examples/ones_difference.stm +19 -19
  13. data/examples/prefix-equals-suffix-reversed-with-infix.stm +33 -33
  14. data/examples/recipe_common.rb +0 -32
  15. data/lib/tins.rb +1 -2
  16. data/lib/tins/annotate.rb +1 -1
  17. data/lib/tins/ask_and_send.rb +16 -0
  18. data/lib/tins/case_predicate.rb +7 -0
  19. data/lib/tins/dslkit.rb +7 -54
  20. data/lib/tins/file_binary.rb +1 -3
  21. data/lib/tins/method_description.rb +4 -2
  22. data/lib/tins/null.rb +1 -1
  23. data/lib/tins/string_version.rb +1 -3
  24. data/lib/tins/terminal.rb +18 -10
  25. data/lib/tins/thread_local.rb +2 -3
  26. data/lib/tins/token.rb +4 -1
  27. data/lib/tins/version.rb +1 -1
  28. data/lib/tins/xt.rb +2 -1
  29. data/lib/tins/xt/case_predicate.rb +8 -0
  30. data/lib/tins/xt/dslkit.rb +0 -1
  31. data/lib/tins/xt/named.rb +14 -26
  32. data/lib/tins/{time_freezer.rb → xt/time_freezer.rb} +0 -0
  33. data/tests/ask_and_send_test.rb +14 -0
  34. data/tests/attempt_test.rb +0 -6
  35. data/tests/case_predicate_test.rb +29 -0
  36. data/tests/dslkit_test.rb +0 -2
  37. data/tests/if_predicate_test.rb +1 -1
  38. data/tests/method_description_test.rb +15 -2
  39. data/tests/test_helper.rb +4 -0
  40. data/tins.gemspec +7 -7
  41. metadata +23 -28
  42. data/examples/bb3_19.stm +0 -26
  43. data/examples/concatenate_compare_19.mtm +0 -31
  44. data/examples/length_difference_19.mtm +0 -17
  45. data/examples/ones_difference_19.mtm +0 -12
  46. data/examples/ones_difference_19.stm +0 -25
  47. data/examples/prefix-equals-suffix-reversed-with-infix_19.stm +0 -38
  48. data/lib/tins/round.rb +0 -51
  49. data/lib/tins/xt/round.rb +0 -13
  50. data/tests/round_test.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac9293571b9bc0ef6b9b69d7ea1f4af100747f7d
4
- data.tar.gz: 9ff3fadf3a3360863b460caae030fa86a115290e
3
+ metadata.gz: aa1bf4ee9dea65d5c11f563451d6642c5fe1884c
4
+ data.tar.gz: 1c7146c7571c21394db79a1d390507b3895e2e44
5
5
  SHA512:
6
- metadata.gz: 0d34fbdf023e7c18188505f1d08f876041b7a36eadfad046b1f01a70e30948e95b64ca1584f31fcfe648b603074b05dad9a4c781292b6b42d16e5f154e0e1791
7
- data.tar.gz: bb7b9e5aa389f4ba20839c1e922e672ba0d4bc1be9bbad8331671d2fe32af22ab97c61792505614a27c3f93c722ebe88379e1a54a3d24eedfcbb4761de36b6c5
6
+ metadata.gz: 19a5df0f5e8e5d13c1a868a369b1aa6e5ef85f75a91e37bf815c0954aefe71f4a602889ee12b37b1c12e8dce3669730ea39bd93620205391ec6012ba9eb16d53
7
+ data.tar.gz: f0d23c8f50f2638bd4d06ecd56abc6fce27036dfdc67573234f02cbe9db9fefe45c8b8ae6dfa8f3e281a35d85931b40b4d813efa31ff79b0c7077cb0d11b4283
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@ rvm:
2
2
  - 1.9.2
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.1
5
+ - 2.1.2
6
6
  - ruby-head
7
7
  - rbx-19mode
8
8
  - jruby-19mode
@@ -11,3 +11,5 @@ matrix:
11
11
  - rvm: ruby-head
12
12
  - rvm: rbx-19mode
13
13
  - rvm: jruby-19mode
14
+ env:
15
+ - CODECLIMATE_REPO_TOKEN=62d082406430ccf662c2e401976b613c0091e26fcfb546f92b1f2b391951cf50
data/Gemfile CHANGED
@@ -6,4 +6,6 @@ gemspec
6
6
 
7
7
  group :development do
8
8
  gem 'simplecov'
9
+ gem 'term-ansicolor'
10
+ gem "codeclimate-test-reporter", group: :test, require: nil
9
11
  end
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Tins - Useful tools library in Ruby
2
+
3
+ ## Description
4
+
5
+ Non yet.
6
+
7
+ ## Badges
8
+
9
+ [![Code Climate](https://codeclimate.com/github/flori/tins.png)](https://codeclimate.com/github/flori/tins)
10
+
11
+ [![Code Coverage](https://codeclimate.com/github/flori/tins/coverage.png)](https://codeclimate.com/github/flori/tins)
12
+
13
+ ## Download
14
+
15
+ The homepage of this library is located at
16
+
17
+ * http://flori.github.com/tins
18
+
19
+ ## Author
20
+
21
+ Florian Frank mailto:flori@ping.de
22
+
23
+ ## License
24
+
25
+ This software is licensed under the MIT (Expat) license.
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ GemHadar do
14
14
  ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage', '.rbx',
15
15
  '.AppleDouble', '.DS_Store', 'tags', '.bundle'
16
16
 
17
- readme 'README.rdoc'
17
+ readme 'README.md'
18
18
  licenses << 'MIT'
19
19
 
20
20
  development_dependency 'test-unit', '~>2.5'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.3.1
data/examples/bb3.stm CHANGED
@@ -5,22 +5,22 @@
5
5
  # Busy Beaver: 3-state, 2-symbol
6
6
 
7
7
  # state A
8
- 1. cond :if => 'B', :then => 2, :else => 4
9
- 2. write :symbol => '1', :goto => 3
10
- 3. right :goto => 6
11
- 4. write :symbol => '1', :goto => 5
12
- 5. right :goto => 16
8
+ 1. cond if: 'B', then: 2, else: 4
9
+ 2. write symbol: '1', goto: 3
10
+ 3. right goto: 6
11
+ 4. write symbol: '1', goto: 5
12
+ 5. right goto: 16
13
13
  # state B
14
- 6. cond :if => 'B', :then => 7, :else => 9
15
- 7. write :symbol => 'B', :goto => 8
16
- 8. right :goto => 11
17
- 9. write :symbol => '1', :goto => 10
18
- 10. right :goto => 6
14
+ 6. cond if: 'B', then: 7, else: 9
15
+ 7. write symbol: 'B', goto: 8
16
+ 8. right goto: 11
17
+ 9. write symbol: '1', goto: 10
18
+ 10. right goto: 6
19
19
  # state C
20
- 11. cond :if => 'B', :then => 12, :else => 14
21
- 12. write :symbol => '1', :goto => 13
22
- 13. left :goto => 11
23
- 14. write :symbol => '1', :goto => 15
24
- 15. left :goto => 1
20
+ 11. cond if: 'B', then: 12, else: 14
21
+ 12. write symbol: '1', goto: 13
22
+ 13. left goto: 11
23
+ 14. write symbol: '1', goto: 15
24
+ 15. left goto: 1
25
25
  # halt
26
26
  16. halt
@@ -2,30 +2,30 @@
2
2
  # Call with four binary numbers on the tape:
3
3
  # $ turing.rb concatenate_compare.mtm 110 1 11 01
4
4
 
5
- 1. right 1, :goto => 2
6
- 2. cond 1, :if => 'B', :then => 3, :else => 1
7
- 3. right 2, :goto => 4
8
- 4. cond 2, :if => '0', :then => 7, :else => 5
9
- 5. cond 2, :if => '1', :then => 6, :else => 9
10
- 6. write 1, :symbol => '1', :goto => 8
11
- 7. write 1, :symbol => '0', :goto => 8
12
- 8. right 1, :goto => 3
13
- 9. right 3, :goto => 10
14
- 10. cond 3, :if => 'B', :then => 11, :else => 9
15
- 11. right 4, :goto => 12
16
- 12. cond 4, :if => '0', :then => 14, :else => 13
17
- 13. cond 4, :if => '1', :then => 15, :else => 17
18
- 14. write 3, :symbol => '0', :goto => 16
19
- 15. write 3, :symbol => '1', :goto => 16
20
- 16. right 3, :goto => 11
21
- 17. left 3, :goto => 18
22
- 18. left 1, :goto => 19
23
- 19. cond 3, :if => '0', :then => 20, :else => 22
24
- 20. cond 1, :if => '0', :then => 17, :else => 24
25
- 21. cond 1, :if => '1', :then => 17, :else => 24
26
- 22. cond 3, :if => '1', :then => 21, :else => 23
27
- 23. cond 1, :if => 'B', :then => 25, :else => 24
28
- 24. write 0, :symbol => '0', :goto => 26
29
- 25. write 0, :symbol => '1', :goto => 26
30
- 26. right 0, :goto => 27
5
+ 1. right 1, goto: 2
6
+ 2. cond 1, if: 'B', then: 3, else: 1
7
+ 3. right 2, goto: 4
8
+ 4. cond 2, if: '0', then: 7, else: 5
9
+ 5. cond 2, if: '1', then: 6, else: 9
10
+ 6. write 1, symbol: '1', goto: 8
11
+ 7. write 1, symbol: '0', goto: 8
12
+ 8. right 1, goto: 3
13
+ 9. right 3, goto: 10
14
+ 10. cond 3, if: 'B', then: 11, else: 9
15
+ 11. right 4, goto: 12
16
+ 12. cond 4, if: '0', then: 14, else: 13
17
+ 13. cond 4, if: '1', then: 15, else: 17
18
+ 14. write 3, symbol: '0', goto: 16
19
+ 15. write 3, symbol: '1', goto: 16
20
+ 16. right 3, goto: 11
21
+ 17. left 3, goto: 18
22
+ 18. left 1, goto: 19
23
+ 19. cond 3, if: '0', then: 20, else: 22
24
+ 20. cond 1, if: '0', then: 17, else: 24
25
+ 21. cond 1, if: '1', then: 17, else: 24
26
+ 22. cond 3, if: '1', then: 21, else: 23
27
+ 23. cond 1, if: 'B', then: 25, else: 24
28
+ 24. write 0, symbol: '0', goto: 26
29
+ 25. write 0, symbol: '1', goto: 26
30
+ 26. right 0, goto: 27
31
31
  27. halt
@@ -2,16 +2,16 @@
2
2
  # Call with two [ab]* strings on the tapes:
3
3
  # $ turing.rb prefix-equals-suffix-reversed-with-infix.stm ab ababab
4
4
 
5
- 1. right 1, :goto => 2
6
- 2. right 2, :goto => 3
7
- 3. cond 1, :if => 'B', :then => 5, :else => 4
8
- 4. cond 2, :if => 'B', :then => 9, :else => 1
9
- 5. cond 2, :if => 'B', :then => 13, :else => 6
10
- 6. write 0, :symbol => 'b', :goto => 7
11
- 7. right 0, :goto => 8
12
- 8. right 2, :goto => 5
13
- 9. write 0, :symbol => 'a', :goto => 10
14
- 10. right 0, :goto => 11
15
- 11. right 1, :goto => 12
16
- 12. cond 1, :if => 'B', :then => 13, :else => 9
5
+ 1. right 1, goto: 2
6
+ 2. right 2, goto: 3
7
+ 3. cond 1, if: 'B', then: 5, else: 4
8
+ 4. cond 2, if: 'B', then: 9, else: 1
9
+ 5. cond 2, if: 'B', then: 13, else: 6
10
+ 6. write 0, symbol: 'b', goto: 7
11
+ 7. right 0, goto: 8
12
+ 8. right 2, goto: 5
13
+ 9. write 0, symbol: 'a', goto: 10
14
+ 10. right 0, goto: 11
15
+ 11. right 1, goto: 12
16
+ 12. cond 1, if: 'B', then: 13, else: 9
17
17
  13. halt
data/examples/let.rb CHANGED
@@ -50,8 +50,8 @@ if $0 == __FILE__
50
50
  end
51
51
 
52
52
  def test
53
- let :x => 1, :y => twice(1) do
54
- let :z => twice(x) do
53
+ let x: 1, y: twice(1) do
54
+ let z: twice(x) do
55
55
  puts "#{x} * #{y} == #{z} # => #{x * y == twice(x)}"
56
56
  end
57
57
  end
@@ -2,11 +2,11 @@
2
2
  # Call with two strings of ones on the tape:
3
3
  # $ turing.rb ones_difference.mtm 1111 11
4
4
 
5
- 0. right 1, :goto => 1
6
- 1. right 2, :goto => 2
7
- 2. cond 1, :if => '1', :then => 3, :else => 4
8
- 3. cond 2, :if => '1', :then => 0, :else => 5
9
- 4. cond 2, :if => '1', :then => 5, :else => 7
10
- 5. write 0, :symbol => '1', :goto => 6
11
- 6. left 0, :goto => 0
5
+ 0. right 1, goto: 1
6
+ 1. right 2, goto: 2
7
+ 2. cond 1, if: '1', then: 3, else: 4
8
+ 3. cond 2, if: '1', then: 0, else: 5
9
+ 4. cond 2, if: '1', then: 5, else: 7
10
+ 5. write 0, symbol: '1', goto: 6
11
+ 6. left 0, goto: 0
12
12
  7. halt
@@ -2,24 +2,24 @@
2
2
  # Call with two strings of ones on the tape:
3
3
  # $ turing.rb ones_difference.stm 1111 11
4
4
 
5
- 1. right :goto => 2
6
- 2. cond :if => '1', :then => 1, :else => 3
7
- 3. right :goto => 4
8
- 4. cond :if => '1', :then => 5, :else => 17
9
- 5. right :goto => 6
10
- 6. cond :if => '1', :then => 5, :else => 7
11
- 7. left :goto => 8
12
- 8. write :symbol => 'B', :goto => 9
13
- 9. left :goto => 10
14
- 10. cond :if => '1', :then => 9, :else => 11
15
- 11. left :goto => 12
16
- 12. cond :if => '1', :then => 11, :else => 13
17
- 13. right :goto => 14
18
- 14. cond :if => '1', :then => 15, :else => 16
19
- 15. write :symbol => 'B', :goto => 1
20
- 16. write :symbol => '1', :goto => 18
21
- 17. left :goto => 20
22
- 18. right :goto => 19
23
- 19. cond :if => '1', :then => 18, :else => 21
5
+ 1. right goto: 2
6
+ 2. cond if: '1', then: 1, else: 3
7
+ 3. right goto: 4
8
+ 4. cond if: '1', then: 5, else: 17
9
+ 5. right goto: 6
10
+ 6. cond if: '1', then: 5, else: 7
11
+ 7. left goto: 8
12
+ 8. write symbol: 'B', goto: 9
13
+ 9. left goto: 10
14
+ 10. cond if: '1', then: 9, else: 11
15
+ 11. left goto: 12
16
+ 12. cond if: '1', then: 11, else: 13
17
+ 13. right goto: 14
18
+ 14. cond if: '1', then: 15, else: 16
19
+ 15. write symbol: 'B', goto: 1
20
+ 16. write symbol: '1', goto: 18
21
+ 17. left goto: 20
22
+ 18. right goto: 19
23
+ 19. cond if: '1', then: 18, else: 21
24
24
  20. halt
25
25
  21. halt
@@ -2,37 +2,37 @@
2
2
  # Call with a binary number on the tape:
3
3
  # $ turing.rb prefix-equals-suffix-reversed-with-infix.stm 100101001
4
4
 
5
- 0. right :goto => 1
6
- 1. cond :if => '0', :then => 2, :else => 13
7
- 2. write :symbol => 'O', :goto => 3
8
- 3. right :goto => 4
9
- 4. cond :if => 'B', :then => 21, :else => 5
10
- 5. right :goto => 6
11
- 6. cond :if => 'B', :then => 7, :else => 5
12
- 7. left :goto => 8
13
- 8. cond :if => '0', :then => 9, :else => 21
14
- 9. write :symbol => 'B', :goto => 10
15
- 10. left :goto => 11
16
- 11. cond :if => '0', :then => 10, :else => 12
17
- 12. cond :if => '1', :then => 10, :else => 0
18
- 13. cond :if => '1', :then => 14, :else => 31
19
- 14. write :symbol => 'I', :goto => 15
20
- 15. right :goto => 16
21
- 16. cond :if => 'B', :then => 21, :else => 17
22
- 17. right :goto => 18
23
- 18. cond :if => 'B', :then => 19, :else => 17
24
- 19. left :goto => 20
25
- 20. cond :if => '1', :then => 9, :else => 21
26
- 21. write :symbol => 'B', :goto => 22
27
- 22. left :goto => 23
28
- 23. cond :if => '0', :then => 21, :else => 24
29
- 24. cond :if => '1', :then => 21, :else => 25
30
- 25. write :symbol => 'B', :goto => 26
31
- 26. left :goto => 27
32
- 27. cond :if => 'O', :then => 29, :else => 28
33
- 28. cond :if => 'I', :then => 30, :else => 32
34
- 29. write :symbol => '0', :goto => 26
35
- 30. write :symbol => '1', :goto => 26
5
+ 0. right goto: 1
6
+ 1. cond if: '0', then: 2, else: 13
7
+ 2. write symbol: 'O', goto: 3
8
+ 3. right goto: 4
9
+ 4. cond if: 'B', then: 21, else: 5
10
+ 5. right goto: 6
11
+ 6. cond if: 'B', then: 7, else: 5
12
+ 7. left goto: 8
13
+ 8. cond if: '0', then: 9, else: 21
14
+ 9. write symbol: 'B', goto: 10
15
+ 10. left goto: 11
16
+ 11. cond if: '0', then: 10, else: 12
17
+ 12. cond if: '1', then: 10, else: 0
18
+ 13. cond if: '1', then: 14, else: 31
19
+ 14. write symbol: 'I', goto: 15
20
+ 15. right goto: 16
21
+ 16. cond if: 'B', then: 21, else: 17
22
+ 17. right goto: 18
23
+ 18. cond if: 'B', then: 19, else: 17
24
+ 19. left goto: 20
25
+ 20. cond if: '1', then: 9, else: 21
26
+ 21. write symbol: 'B', goto: 22
27
+ 22. left goto: 23
28
+ 23. cond if: '0', then: 21, else: 24
29
+ 24. cond if: '1', then: 21, else: 25
30
+ 25. write symbol: 'B', goto: 26
31
+ 26. left goto: 27
32
+ 27. cond if: 'O', then: 29, else: 28
33
+ 28. cond if: 'I', then: 30, else: 32
34
+ 29. write symbol: '0', goto: 26
35
+ 30. write symbol: '1', goto: 26
36
36
  31. halt
37
- 32. right :goto => 33
38
- 33. cond :if => 'B', :then => 31, :else => 32
37
+ 32. right goto: 33
38
+ 33. cond if: 'B', then: 31, else: 32
@@ -63,35 +63,3 @@ class Unit
63
63
  "#@n #{name}#{@n > 1 ? 's' : ''}"
64
64
  end
65
65
  end
66
-
67
- class Unit
68
- class << self
69
- def inherited(klass)
70
- units << klass
71
- end
72
-
73
- attr_accessor :units
74
-
75
- def unit(name, amount)
76
- name = name.to_s.gsub(/s$/, '').capitalize
77
- if klass = units.find { |n| n.to_s == name }
78
- klass.new(amount)
79
- end
80
- end
81
- end
82
- self.units = []
83
-
84
- def initialize(n = 1)
85
- @n = n
86
- end
87
-
88
- def name
89
- self.class.name.downcase
90
- end
91
-
92
- attr_reader :n
93
-
94
- def to_s
95
- "#@n #{name}#{@n > 1 ? 's' : ''}"
96
- end
97
- end
data/lib/tins.rb CHANGED
@@ -20,7 +20,6 @@ module Tins
20
20
  require 'tins/partial_application'
21
21
  require 'tins/range_plus'
22
22
  require 'tins/require_maybe'
23
- require 'tins/round'
24
23
  require 'tins/secure_write'
25
24
  require 'tins/shuffle'
26
25
  require 'tins/string_camelize'
@@ -30,7 +29,6 @@ module Tins
30
29
  require 'tins/time_dummy'
31
30
  require 'tins/date_dummy'
32
31
  require 'tins/date_time_dummy'
33
- require 'tins/time_freezer'
34
32
  require 'tins/to_proc'
35
33
  require 'tins/uniq_by'
36
34
  require 'tins/version'
@@ -49,6 +47,7 @@ module Tins
49
47
  require 'tins/annotate'
50
48
  require 'tins/token'
51
49
  require 'tins/dslkit'
50
+ require 'tins/case_predicate'
52
51
  if defined? ::Encoding
53
52
  require 'tins/string_byte_order_mark'
54
53
  end
data/lib/tins/annotate.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Tins::Annotate
2
2
  def annotate(name)
3
- class << self; self; end.class_eval do
3
+ singleton_class.class_eval do
4
4
  define_method(name) do |annotation|
5
5
  instance_variable_set "@__annotation_#{name}__", annotation
6
6
  end
@@ -11,5 +11,21 @@ module Tins
11
11
  __send__(method_name, *args, &block)
12
12
  end
13
13
  end
14
+
15
+ def ask_and_send_or_self(method_name, *args, &block)
16
+ if respond_to?(method_name)
17
+ __send__(method_name, *args, &block)
18
+ else
19
+ self
20
+ end
21
+ end
22
+
23
+ def ask_and_send_or_self!(method_name, *args, &block)
24
+ if respond_to?(method_name, true)
25
+ __send__(method_name, *args, &block)
26
+ else
27
+ self
28
+ end
29
+ end
14
30
  end
15
31
  end
@@ -0,0 +1,7 @@
1
+ module Tins
2
+ module CasePredicate
3
+ def case?(*args)
4
+ args.find { |a| a === self }
5
+ end
6
+ end
7
+ end