css-class-string 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 087d76227ff9a92cd7ed27eb1ccdfb1b2972f99f
4
- data.tar.gz: 826c3459f507ac8629e97daf80a65821cf07476c
3
+ metadata.gz: 34a27b73b123c2df9943e743990632312e8d5409
4
+ data.tar.gz: 79d2ed4e547d85e1b107793fdd8a4a7e753acad8
5
5
  SHA512:
6
- metadata.gz: c252d6ee17978b8757424e71cde5adcafc6736b89fa098ffb2489f05ead2e8ed571e49085c02ad2da608729bcad2ec5a3b69138389f861e5315aa41f668eae58
7
- data.tar.gz: 4e2feb72c377a544c2c5010f8daa3d825ff81e9ab78fc8e4d96c400d64295782f37acec9c82464eb6732765c1a38564a8cc4240209c2a2a9b36f82a9bef6b831
6
+ metadata.gz: 3d1fe5f9bf7193cfba0561e41807681c98582bcce5270a690ebeb17c0b36c772896a4ebd58fa4a17ff37ded70c6cd5a836a59410470e052657fc7be7ac591107
7
+ data.tar.gz: d0e8f0611b0d3729cc62ea115fa25a576edff818a588c10ed485c87a1ede22a71b60f7b118e0200a82f2286aa6eee9cd11091788d079c9d69b750c82f12883b8
@@ -5,15 +5,7 @@ module CssClassString
5
5
  end
6
6
 
7
7
  def to_s
8
- @class_hash.inject({}) {|memo, (k, v)|
9
- if k.is_a?(Array)
10
- memo.merge({k[0] => v, k[1] => !v})
11
- else
12
- memo.merge({k => v})
13
- end
14
- }.map {|class_name, present|
15
- class_name if present
16
- }.compact.join(" ")
8
+ @class_hash.map { |((tc, fc), v)| v ? tc : fc }.compact.join(" ")
17
9
  end
18
10
  end
19
11
  end
@@ -1,3 +1,3 @@
1
1
  module CssClassString
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,43 @@
1
+ require 'benchmark'
2
+ require 'securerandom'
3
+ require 'css_class_string/view_helpers'
4
+ include CssClassString::ViewHelpers
5
+
6
+ NUM_CALLS = 40_000
7
+
8
+ def class_name
9
+ SecureRandom.hex(4)
10
+ end
11
+
12
+ def true_or_false
13
+ [true, false].sample
14
+ end
15
+
16
+ arrays = Enumerator.new { |y| y << [[class_name, class_name], true_or_false] }
17
+ strings = Enumerator.new { |y| y << [class_name, true_or_false] }
18
+
19
+ Benchmark.bm do |b|
20
+ b.report("With 1 array and 1 string values") do
21
+ NUM_CALLS.times do
22
+ class_string(Hash[arrays.take(1) + strings.take(1)])
23
+ end
24
+ end
25
+
26
+ b.report("With 5 array and 5 string values") do
27
+ NUM_CALLS.times do
28
+ class_string(Hash[arrays.take(5) + strings.take(5)])
29
+ end
30
+ end
31
+
32
+ b.report("With 10 array values") do
33
+ NUM_CALLS.times do
34
+ class_string(Hash[arrays.take(10)])
35
+ end
36
+ end
37
+
38
+ b.report("With 10 string values") do
39
+ NUM_CALLS.times do
40
+ class_string(Hash[strings.take(10)])
41
+ end
42
+ end
43
+ end
@@ -8,14 +8,14 @@ describe "CssClassString::Helper" do
8
8
  let(:hash) { {truthy: true} }
9
9
  subject { CssClassString::Helper.new(hash).to_s }
10
10
 
11
- it { should eq("truthy") }
11
+ it { is_expected.to eq("truthy") }
12
12
  end
13
13
 
14
14
  context "when a key's value is falsy" do
15
15
  let(:hash) { {falsy: false} }
16
16
  subject { CssClassString::Helper.new(hash).to_s }
17
17
 
18
- it { should eq("") }
18
+ it { is_expected.to eq("") }
19
19
  end
20
20
 
21
21
  context "when a key is an array of two elements" do
@@ -24,17 +24,34 @@ describe "CssClassString::Helper" do
24
24
  let(:hash) { {[:truthy, :falsy] => true} }
25
25
  subject { CssClassString::Helper.new(hash).to_s }
26
26
 
27
- it { should eq("truthy") }
27
+ it { is_expected.to eq("truthy") }
28
28
  end
29
29
 
30
30
  context "when value is falsy" do
31
31
  let(:hash) { {[:truthy, :falsy] => false} }
32
32
  subject { CssClassString::Helper.new(hash).to_s }
33
33
 
34
- it { should eq("falsy") }
34
+ it { is_expected.to eq("falsy") }
35
35
  end
36
36
 
37
37
  end
38
38
 
39
+ context 'when multiple keys are given' do
40
+
41
+ let(:hash) {
42
+ {
43
+ [:arr_truthy, :arr_falsy] => false,
44
+ :str_truthy => true,
45
+ :str_falsy => false
46
+ }
47
+ }
48
+ subject { CssClassString::Helper.new(hash).to_s }
49
+
50
+ it { is_expected.to match(/^\w+ \w+$/) }
51
+ it { is_expected.to include('arr_falsy', 'str_truthy') }
52
+ it { is_expected.not_to include('arr_truthy', 'str_falsy') }
53
+
54
+ end
55
+
39
56
  end
40
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: css-class-string
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Rozhkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-10 00:00:00.000000000 Z
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,7 @@ files:
72
72
  - lib/css_class_string/railtie.rb
73
73
  - lib/css_class_string/version.rb
74
74
  - lib/css_class_string/view_helpers.rb
75
+ - profiling/benchmark.rb
75
76
  - spec/css_class_string/helper_spec.rb
76
77
  - spec/spec_helper.rb
77
78
  homepage: https://github.com/nLight/css-class-string