sugar-high 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.4.4
@@ -4,11 +4,16 @@ require 'sugar-high/path'
4
4
 
5
5
  class Array
6
6
  def to_symbols
7
- self.flatten.select_labels.map{|a| a.to_s.to_sym }
7
+ res = self.flatten.select_labels
8
+ res = res.map{|a| a.to_s.to_sym } if res
9
+ res || []
8
10
  end
9
11
 
10
12
  def to_symbols!
11
- self.flatten!.select_labels!.map!{|a| a.to_s.to_sym }
13
+ self.flatten!
14
+ self.select_labels!
15
+ self.map!{|a| a.to_s.to_sym }
16
+ self
12
17
  end
13
18
 
14
19
  def to_symbols_num
@@ -16,7 +21,8 @@ class Array
16
21
  end
17
22
 
18
23
  def to_symbols_num!
19
- self.flatten!.map!{|a| a.kind_of?(Fixnum) ? "_#{a}" : a}..map!{|a| a.to_s.to_sym }
24
+ self.flatten!
25
+ self.map!{|a| a.kind_of?(Fixnum) ? "_#{a}" : a}.map!{|a| a.to_s.to_sym }
20
26
  end
21
27
 
22
28
  def to_symbols_uniq
@@ -24,15 +30,16 @@ class Array
24
30
  end
25
31
 
26
32
  def to_symbols_uniq!
27
- to_symbols!.uniq!
33
+ self.to_symbols!.uniq!
28
34
  end
29
35
 
30
- def to_strings
31
- self.flatten!.select_labels!.map!(&:to_s)
36
+ def to_strings!
37
+ self.flatten!
38
+ self.select_labels!.map!(&:to_s)
32
39
  end
33
40
 
34
- def to_strings!
35
- self.flatten.select_labels!.map!(&:to_s)
41
+ def to_strings
42
+ self.flatten.select_labels.map(&:to_s)
36
43
  end
37
44
 
38
45
  def to_filenames
@@ -49,6 +56,7 @@ class Array
49
56
 
50
57
  def to_paths!
51
58
  self.map!(&:path)
59
+ self
52
60
  end
53
61
 
54
62
  def file_join
@@ -74,7 +82,10 @@ class Array
74
82
  end
75
83
 
76
84
  def flat_uniq!
77
- self.flatten!.compact!.uniq!
85
+ self.flatten!
86
+ self.compact!
87
+ self.uniq!
88
+ self
78
89
  end
79
90
 
80
91
  def extract(sym)
@@ -13,6 +13,7 @@ module Enumerable
13
13
 
14
14
  def select_kinds_of! *kinds
15
15
  select!{|a| a.any_kind_of? *kinds }
16
+ self
16
17
  end
17
18
 
18
19
  def select_labels
@@ -20,7 +21,8 @@ module Enumerable
20
21
  end
21
22
 
22
23
  def select_labels!
23
- select! {|a| a.kind_of_label? }
24
+ select!{|a| a.kind_of_label? }
25
+ self
24
26
  end
25
27
 
26
28
 
@@ -30,18 +32,21 @@ module Enumerable
30
32
 
31
33
  def select_symbols!
32
34
  select_only! :symbol
35
+ self
33
36
  end
34
37
 
35
38
  def select_uniq_symbols!
36
39
  select_only!(:symbol).uniq!
40
+ self
37
41
  end
38
42
 
39
43
  def select_strings
40
44
  select_only :string
41
45
  end
42
46
 
43
- def select_strings
44
- select_only :string
47
+ def select_strings!
48
+ select_only! :string
49
+ self
45
50
  end
46
51
 
47
52
  def select_only type
@@ -52,6 +57,7 @@ module Enumerable
52
57
  def select_only! type
53
58
  const = type.kind_of_label? ? "#{type.to_s.camelize}".constantize : type
54
59
  select!{|a| a.kind_of? const}
60
+ self
55
61
  end
56
62
 
57
63
  def all_kinds
@@ -5,6 +5,10 @@ describe "SugarHigh" do
5
5
  describe "Array ext" do
6
6
 
7
7
  describe '#to_symbols' do
8
+ it "should translate invalid array into empty array" do
9
+ [1, nil].to_symbols.should == []
10
+ end
11
+
8
12
  it "should translate nested array of numbers and strings into symbols only array, excluding numbers" do
9
13
  [1, 'blip', [3, "hello"]].to_symbols.should == [:blip, :hello]
10
14
  end
@@ -23,6 +27,11 @@ describe "SugarHigh" do
23
27
  x = [1, 'hello', 'blip', [3, "hello"]].to_symbols!
24
28
  x.should include :hello, :blip
25
29
  end
30
+
31
+ it "should translate invalid array into empty array" do
32
+ x = [1, nil].to_symbols!
33
+ x.should == []
34
+ end
26
35
  end
27
36
 
28
37
  describe '#to_strings' do
@@ -31,7 +40,12 @@ describe "SugarHigh" do
31
40
  end
32
41
  end
33
42
 
34
- describe '#to_strings!' do
43
+ describe '#to_strings' do
44
+ it "should translate invalid array into empty array" do
45
+ x = [1, nil].to_strings!
46
+ x.should == []
47
+ end
48
+
35
49
  it "should translate nested array of numbers and strings into symbols only array, excluding numbers" do
36
50
  x = [1, 'blip', [3, "hello"]].to_strings!
37
51
  x.should == ['blip', 'hello']
@@ -49,6 +63,11 @@ describe "SugarHigh" do
49
63
  end
50
64
 
51
65
  describe '#flat_uniq!' do
66
+ it "should translate invalid array into empty array" do
67
+ x = [1, nil].to_strings!
68
+ x.should == []
69
+ end
70
+
52
71
  it "should flatten array, remove nils and make unique" do
53
72
  x = [1, 'blip', ['blip', nil, 'c'], nil]
54
73
  x.flat_uniq!
data/sugar-high.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sugar-high}
8
- s.version = "0.4.3"
8
+ s.version = "0.4.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Kristian Mandrup}]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugar-high
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-06-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2154101200 !ruby/object:Gem::Requirement
16
+ requirement: &2153218060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.4.1
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2154101200
24
+ version_requirements: *2153218060
25
25
  description: More Ruby sugar - inspired by the 'zuker' project
26
26
  email: kmandrup@gmail.com
27
27
  executables: []