sugar-high 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -69,9 +69,12 @@ PathString:
69
69
 
70
70
  Create empty namespaces
71
71
 
72
- ### String
72
+ ### Blank
73
73
 
74
- * blank?
74
+ * blank? : Empty string? (works on nil)
75
+ * wblank? : Blank including whitespace only? (works on nil)
76
+ * empty? : array and nil
77
+ * any? : array and nil
75
78
 
76
79
  ## RSpec 2 Matchers
77
80
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -0,0 +1,12 @@
1
+ class Array
2
+ def to_symbols option=nil
3
+ res = self.flatten
4
+ res = case option
5
+ when :num
6
+ res.map{|a| a.kind_of?(Fixnum) ? "_#{a}" : a}
7
+ else
8
+ res.reject{|a| a.kind_of? Fixnum}
9
+ end
10
+ res.map(&:to_s).map(&:to_sym)
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ class NilClass
2
+ def blank?
3
+ true
4
+ end
5
+ alias_method :wblank?, :blank?
6
+ alias_method :empty?, :blank?
7
+
8
+ def any?
9
+ false
10
+ end
11
+ end
12
+
13
+ class String
14
+ def blank?
15
+ self.empty?
16
+ end
17
+
18
+ def wblank?
19
+ self.strip.blank?
20
+ end
21
+ end
22
+
@@ -1,7 +1,7 @@
1
1
  class Object
2
2
  def any_kind_of? *kinds
3
- kinds.each do |kind|
4
- return true if self.kind_of? kind
3
+ kinds.all_kinds.each do |kind|
4
+ return true if self.kind_of? kind
5
5
  end
6
6
  false
7
7
  end
@@ -9,4 +9,41 @@ class Object
9
9
  def kind_of_label?
10
10
  self.any_kind_of? String, Symbol
11
11
  end
12
+
13
+ def kind_of_symbol?
14
+ self.any_kind_of? Symbols, Symbol
15
+ end
16
+ end
17
+
18
+ module Enumerable
19
+ def only_kinds_of? *kinds
20
+ all?{|a| a.any_kind_of? *kinds }
21
+ end
22
+
23
+ def only_labels?
24
+ all?{|a| a.kind_of_label? }
25
+ end
26
+
27
+ def select_kinds_of *kinds
28
+ select{|a| a.any_kind_of? *kinds }
29
+ end
30
+
31
+ def all_kinds
32
+ map do |a|
33
+ case a
34
+ when Kinds
35
+ a.kinds
36
+ else
37
+ a if a.kind_of?(Module)
38
+ end
39
+ end.compact.uniq.flatten
40
+ end
41
+ end
42
+
43
+ class Kinds
44
+ attr_accessor :kinds
45
+
46
+ def initialize *kinds
47
+ self.kinds = *kinds
48
+ end
12
49
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'sugar-high/array'
3
+
4
+ describe "SugarHigh" do
5
+ describe "Array ext" do
6
+ describe '#to_symbols' do
7
+ it "should translate nested array of numbers and strings into symbols only array, excluding numbers" do
8
+ [1, 'blip', [3, "hello"]].to_symbols.should == [:blip, :hello]
9
+ end
10
+
11
+ it "should translate nested array of numbers and strings into symbols only array, including numbers" do
12
+ [1, 'blip', [3, "hello"]].to_symbols(:num).should == [:_1, :blip, :_3, :hello]
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'sugar-high/blank'
3
+
4
+ describe "SugarHigh" do
5
+ describe "Blank ext" do
6
+ describe '#blank' do
7
+ it "nil and empty string should be blank" do
8
+ nil.blank?.should be_true
9
+ ''.blank?.should be_true
10
+ end
11
+ end
12
+
13
+ describe '#wblank' do
14
+ it "nil and empty string should be blank" do
15
+ nil.wblank?.should be_true
16
+ ' '.wblank?.should be_true
17
+ end
18
+ end
19
+
20
+ describe '#empty' do
21
+ it "nil and empty string should be empty" do
22
+ nil.empty?.should be_true
23
+ ''.empty?.should be_true
24
+ end
25
+
26
+ context 'Array' do
27
+ it "nil and empty array should not have any" do
28
+ nil.any?.should be_false
29
+ [].any?.should be_false
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -13,36 +13,108 @@ describe "SugarHigh" do
13
13
  @obj.any_kind_of?(String, Symbol).should be_false
14
14
  end
15
15
  end
16
-
16
+
17
17
  context 'a String and a Symbol' do
18
18
  before do
19
19
  @obj_str = "Hello"
20
20
  @obj_sym = :hello
21
21
  end
22
-
22
+
23
23
  it "should return true for a String" do
24
24
  @obj_str.any_kind_of?(String, Symbol).should be_true
25
25
  end
26
-
26
+
27
27
  it "should return true for a File" do
28
28
  @obj_sym.any_kind_of?(String, Symbol).should be_true
29
29
  end
30
30
  end
31
31
  end
32
-
32
+
33
+ describe '#only_kind_of?' do
34
+ context 'labels and Fix numbers' do
35
+ before do
36
+ @valid_list = ["Hello", :hello, 7]
37
+ @bad_list = [ {:a => 4}, 'blip']
38
+ end
39
+
40
+ it "should be true for a list of labels and Fix numbers" do
41
+ @valid_list.only_kinds_of?(String, Symbol, Fixnum).should be_true
42
+ end
43
+
44
+ it "should be false for a list with a Hash" do
45
+ @bad_list.only_kinds_of?(String, Symbol, Fixnum).should be_false
46
+ end
47
+ end
48
+ end
49
+
50
+
33
51
  describe '#kind_of_label?' do
34
52
  before do
35
53
  @obj_str = "Hello"
36
54
  @obj_sym = :hello
55
+ @label_list = [@obj_str, @obj_sym]
56
+ @mix_list = [@obj_str, @obj_sym, 27]
37
57
  end
38
-
58
+
39
59
  it "should return true for a String" do
40
60
  @obj_str.kind_of_label?.should be_true
41
61
  end
42
-
43
- it "should return true for a File" do
62
+
63
+ it "should return true for a Symbol" do
44
64
  @obj_sym.kind_of_label?.should be_true
45
65
  end
66
+
67
+ it "should return true for a list of String and Symbols" do
68
+ @label_list.only_labels?.should be_true
69
+ end
70
+
71
+ it "should return false for a list of with non-label types" do
72
+ @mix_list.only_labels?.should be_false
73
+ end
74
+ end
75
+
76
+ describe '#select_kinds_of' do
77
+ before do
78
+ @obj_str = "Hello"
79
+ @obj_sym = :hello
80
+ @label_list = [@obj_str, @obj_sym]
81
+ @mix_list = [@obj_str, @obj_sym, 27]
82
+ end
83
+
84
+ it "should select all Symbols in list" do
85
+ @label_list.select_kinds_of(Symbol).should == [:hello]
86
+ end
87
+ end
88
+
89
+ context 'Symbols object' do
90
+ describe '#select_kinds_of' do
91
+ before do
92
+ @obj_str = "Hello"
93
+ @obj_sym = :hello
94
+ @label_kinds = Kinds.new Symbol, String
95
+ @label_list = [@obj_str, @obj_sym]
96
+ @mix_list = [@obj_str, @obj_sym, 27]
97
+ end
98
+
99
+ it "should select all Symbols in list" do
100
+ @mix_list.select_kinds_of(@label_kinds).should == ["Hello", :hello]
101
+ end
102
+ end
103
+ end
104
+
105
+ describe '#all_symbols' do
106
+ before do
107
+ @obj_str = "Hello"
108
+ @obj_sym = :hello
109
+ @label_kinds = Kinds.new Symbol, String
110
+ @label_list = [@obj_str, @obj_sym, @label_kinds]
111
+ end
112
+
113
+ it "should return true for a String" do
114
+ # puts "label_kinds: #{@label_kinds.kinds}"
115
+ # puts "all kinds: #{@label_list.all_kinds}"
116
+ @label_list.all_kinds.should == [Symbol, String]
117
+ end
46
118
  end
47
119
  end
48
120
  end
data/sugar-high.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sugar-high}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2010-08-25}
12
+ s.date = %q{2010-08-26}
13
13
  s.description = %q{More Ruby sugar - inspired by the 'zuker' project}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,8 @@ Gem::Specification.new do |s|
27
27
  "lib/sugar-high.rb",
28
28
  "lib/sugar-high/alias.rb",
29
29
  "lib/sugar-high/arguments.rb",
30
+ "lib/sugar-high/array.rb",
31
+ "lib/sugar-high/blank.rb",
30
32
  "lib/sugar-high/file.rb",
31
33
  "lib/sugar-high/hash.rb",
32
34
  "lib/sugar-high/includes.rb",
@@ -36,12 +38,13 @@ Gem::Specification.new do |s|
36
38
  "lib/sugar-high/methods.rb",
37
39
  "lib/sugar-high/module.rb",
38
40
  "lib/sugar-high/rspec.rb",
39
- "lib/sugar-high/string.rb",
40
41
  "spec/fixtures/empty.txt",
41
42
  "spec/fixtures/non-empty.txt",
42
43
  "spec/spec_helper.rb",
43
44
  "spec/sugar-high/alias_spec.rb",
44
45
  "spec/sugar-high/arguments_spec.rb",
46
+ "spec/sugar-high/array_spec.rb",
47
+ "spec/sugar-high/blank_spec.rb",
45
48
  "spec/sugar-high/file_spec.rb",
46
49
  "spec/sugar-high/includes_spec.rb",
47
50
  "spec/sugar-high/kind_of_spec.rb",
@@ -58,6 +61,8 @@ Gem::Specification.new do |s|
58
61
  "spec/spec_helper.rb",
59
62
  "spec/sugar-high/alias_spec.rb",
60
63
  "spec/sugar-high/arguments_spec.rb",
64
+ "spec/sugar-high/array_spec.rb",
65
+ "spec/sugar-high/blank_spec.rb",
61
66
  "spec/sugar-high/file_spec.rb",
62
67
  "spec/sugar-high/includes_spec.rb",
63
68
  "spec/sugar-high/kind_of_spec.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-25 00:00:00 +02:00
17
+ date: 2010-08-26 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -54,6 +54,8 @@ files:
54
54
  - lib/sugar-high.rb
55
55
  - lib/sugar-high/alias.rb
56
56
  - lib/sugar-high/arguments.rb
57
+ - lib/sugar-high/array.rb
58
+ - lib/sugar-high/blank.rb
57
59
  - lib/sugar-high/file.rb
58
60
  - lib/sugar-high/hash.rb
59
61
  - lib/sugar-high/includes.rb
@@ -63,12 +65,13 @@ files:
63
65
  - lib/sugar-high/methods.rb
64
66
  - lib/sugar-high/module.rb
65
67
  - lib/sugar-high/rspec.rb
66
- - lib/sugar-high/string.rb
67
68
  - spec/fixtures/empty.txt
68
69
  - spec/fixtures/non-empty.txt
69
70
  - spec/spec_helper.rb
70
71
  - spec/sugar-high/alias_spec.rb
71
72
  - spec/sugar-high/arguments_spec.rb
73
+ - spec/sugar-high/array_spec.rb
74
+ - spec/sugar-high/blank_spec.rb
72
75
  - spec/sugar-high/file_spec.rb
73
76
  - spec/sugar-high/includes_spec.rb
74
77
  - spec/sugar-high/kind_of_spec.rb
@@ -111,6 +114,8 @@ test_files:
111
114
  - spec/spec_helper.rb
112
115
  - spec/sugar-high/alias_spec.rb
113
116
  - spec/sugar-high/arguments_spec.rb
117
+ - spec/sugar-high/array_spec.rb
118
+ - spec/sugar-high/blank_spec.rb
114
119
  - spec/sugar-high/file_spec.rb
115
120
  - spec/sugar-high/includes_spec.rb
116
121
  - spec/sugar-high/kind_of_spec.rb
@@ -1,11 +0,0 @@
1
- class NilClass
2
- def blank?
3
- true
4
- end
5
- end
6
-
7
- class String
8
- def blank?
9
- self.empty?
10
- end
11
- end