whats_up 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +18 -18
  2. data/lib/whats_up/version.rb +1 -1
  3. data/lib/whats_up.rb +13 -15
  4. metadata +1 -1
data/README.md CHANGED
@@ -15,26 +15,26 @@ Ever asked: "if I have an object, what method can I call on it to get that resul
15
15
  See if this suits your console cravings:
16
16
 
17
17
  > 3.45.what_equals 3
18
- 3.45.to_i() == 3
19
- 3.45.to_int() == 3
20
- 3.45.floor() == 3
21
- 3.45.round() == 3
22
- 3.45.truncate() == 3
18
+ 3.45.to_i == 3
19
+ 3.45.to_int == 3
20
+ 3.45.floor == 3
21
+ 3.45.round == 3
22
+ 3.45.truncate == 3
23
23
  => {:to_i=>3, :to_int=>3, :floor=>3, :round=>3, :truncate=>3}
24
24
 
25
25
  > 3.45.what_equals 4
26
- 3.45.ceil() == 4
26
+ 3.45.ceil == 4
27
27
  => {:ceil=>4}
28
28
 
29
29
  > 3.55.what_equals 4
30
- 3.55.ceil() == 4
31
- 3.55.round() == 4
30
+ 3.55.ceil == 4
31
+ 3.55.round == 4
32
32
  => {:ceil=>4, :round=>4}
33
33
 
34
34
  > 3.45.what_equals /\n/
35
- 3.45.psych_to_yaml() == "--- 3.45\n...\n"
36
- 3.45.to_yaml() == "--- 3.45\n...\n"
37
- 3.45.pretty_inspect() == "3.45\n"
35
+ 3.45.psych_to_yaml == "--- 3.45\n...\n"
36
+ 3.45.to_yaml == "--- 3.45\n...\n"
37
+ 3.45.pretty_inspect == "3.45\n"
38
38
  => {:psych_to_yaml=>"--- 3.45\n...\n", :to_yaml=>"--- 3.45\n...\n", :pretty_inspect=>"3.45\n"}
39
39
 
40
40
  > 3.what_equals 4, 1
@@ -56,16 +56,16 @@ Note also the addition of helpers like `whats_exactly`, which will only find exa
56
56
  `what_matches`, which will match a regular expression:
57
57
 
58
58
  > 5.whats_exactly 5.0
59
- 5.to_f() == 5.0
59
+ 5.to_f == 5.0
60
60
  => {:to_f=>5.0}
61
61
 
62
62
  > "hello".what_matches /^\d$/
63
- "hello".length() == 5
64
- "hello".size() == 5
65
- "hello".bytesize() == 5
66
- "hello".to_i() == 0
67
- "hello".hex() == 0
68
- "hello".oct() == 0
63
+ "hello".length == 5
64
+ "hello".size == 5
65
+ "hello".bytesize == 5
66
+ "hello".to_i == 0
67
+ "hello".hex == 0
68
+ "hello".oct == 0
69
69
  => {:length=>5, :size=>5, :bytesize=>5, :to_i=>0, :hex=>0, :oct=>0}
70
70
 
71
71
  And if you just want to know everything, I've added `what_works_with` that lists the results of all
@@ -1,4 +1,4 @@
1
1
  module WhatsUp
2
2
  # The current version
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.2"
4
4
  end
data/lib/whats_up.rb CHANGED
@@ -77,19 +77,20 @@ module WhatsUp
77
77
  class << self
78
78
  def build_check_lambda(expected_result, opts = {})
79
79
  if opts[:force_regex]
80
- -> a, b { a === b.to_s }
80
+ expected_result = Regexp.new(expected_result.to_s) unless expected_result.is_a?(Regexp)
81
+ -> value { expected_result === value.to_s }
81
82
  elsif expected_result.is_a?(Regexp) && !opts[:force_exact]
82
- -> a, b { a === b.to_s }
83
+ -> value { expected_result === value.to_s }
83
84
  elsif opts[:force_exact]
84
- -> a, b { a.eql?(b) }
85
+ -> value { expected_result.eql?(value) }
85
86
  elsif opts[:show_all]
86
87
  if opts[:exclude_blank]
87
- -> a, b { !b.nil? && !b.empty? }
88
+ -> value { !value.nil? && !value.empty? }
88
89
  else
89
- -> a, b { true }
90
+ -> value { true }
90
91
  end
91
92
  else
92
- -> a, b { a == b }
93
+ -> value { expected_result == value }
93
94
  end
94
95
  end
95
96
 
@@ -97,17 +98,12 @@ module WhatsUp
97
98
  def find(an_object, expected_result, opts = {}, *args, &block)
98
99
  check_result = build_check_lambda(expected_result, opts)
99
100
 
100
- if opts[:force_regex] && expected_result.is_a?(String)
101
- expected_result = Regexp.new(expected_result)
102
- end
103
-
104
101
  # Prevent any writing to the terminal
105
102
  stdout, stderr = $stdout, $stderr
106
103
  $stdout = $stderr = DummyOut.new
107
104
 
108
- methods = an_object.methods
109
-
110
105
  # Use only methods with valid arity that aren't blacklisted
106
+ methods = an_object.methods
111
107
  methods.select! { |n| an_object.method(n).arity <= args.size && !@@blacklist.include?(n) }
112
108
 
113
109
  # Collect all methods equaling the expected result
@@ -115,7 +111,7 @@ module WhatsUp
115
111
  begin
116
112
  stdout.print ""
117
113
  value = an_object.clone.method(name).call(*args, &block)
118
- res[name] = value if check_result.call(expected_result, value)
114
+ res[name] = value if check_result.call(value)
119
115
  rescue
120
116
  end
121
117
  res
@@ -183,8 +179,10 @@ module WhatsUp
183
179
  full = object.inspect
184
180
 
185
181
  if full.length > max_length
186
- left_cutoff = (max_length - 5) * 2 / 3.0
187
- right_cutoff = max_length - 6 - left_cutoff
182
+ available_length = max_length - 5 # to account for the " ... "
183
+ left_cutoff = available_length * 2 / 3.0
184
+ right_cutoff = available_length - left_cutoff - 1
185
+
188
186
  "#{full[0..left_cutoff]} ... #{full[-right_cutoff..-1]}"
189
187
  else
190
188
  full
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whats_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: