sugar-high 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/.document CHANGED
File without changes
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/LICENSE CHANGED
File without changes
data/README.markdown CHANGED
File without changes
data/Rakefile CHANGED
File without changes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.4
data/lib/sugar-high.rb CHANGED
File without changes
File without changes
File without changes
@@ -3,12 +3,11 @@ require 'sugar-high/kind_of'
3
3
  class Array
4
4
  def to_symbols option=nil
5
5
  res = self.flatten
6
- res = case option
7
- when :num
8
- res.map{|a| a.kind_of?(Fixnum) ? "_#{a}" : a}
9
- else
10
- res.reject{|a| a.kind_of? Fixnum}
11
- end
12
- res.map(&:to_s).map(&:to_sym)
6
+ res.map!{|a| a.kind_of?(Fixnum) ? "_#{a}" : a} if option == :num
7
+ res.select_labels.map(&:to_s).map(&:to_sym)
8
+ end
9
+
10
+ def to_strings option=nil
11
+ self.select_labels.map(&:to_s)
13
12
  end
14
13
  end
File without changes
@@ -35,6 +35,10 @@ class File
35
35
  f.puts content ||= yield
36
36
  end
37
37
  end
38
+
39
+ def self.remove_from file_name, content, &block
40
+ replace_content_from file_name, :content => content, :with => '', &block
41
+ end
38
42
 
39
43
  # replaces content found at replacement_expr with content resulting from yielding block
40
44
  # File.replace_content_from 'myfile.txt', where => /HelloWorld/, with => 'GoodBye'
@@ -150,7 +154,7 @@ class File
150
154
  when String
151
155
  args.first
152
156
  when Hash
153
- options[:content] || yield if block
157
+ options[:content] || (yield if block)
154
158
  else
155
159
  return yield if block
156
160
  raise ArgumentError, "You must supply content to insert, either as a String before the options hash, a :content option or a block"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/spec/spec_helper.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -46,6 +46,18 @@ describe "SugarHigh::File" do
46
46
  end
47
47
  end
48
48
 
49
+ describe '#remove_from with String/Regexp argument that is content to remove' do
50
+ let(:replace_file) { fixture_file 'file.txt' }
51
+
52
+ it "should remove content from existing file" do
53
+ File.overwrite(replace_file) do
54
+ 'Hello You'
55
+ end
56
+ File.remove_from replace_file, 'You'
57
+ File.read(replace_file).should_not match /You/
58
+ end
59
+ end
60
+
49
61
 
50
62
  describe '#insert_into' do
51
63
  let(:insertion_file) { fixture_file 'insertion.txt' }
@@ -64,28 +76,29 @@ describe "SugarHigh::File" do
64
76
  File.insert_into insertion_file, :before => 'Goodbye' do
65
77
  'Hello'
66
78
  end
79
+ File.read(insertion_file).should match /Hello\s+Goodbye/
67
80
  end
68
81
 
69
82
  it "should insert Hello before Goodbye using a content string arg" do
70
83
  File.insert_into insertion_file, "Hello ", :before => 'Goodbye'
71
- File.read(insertion_file).should_not match /Hello Goodbye/
84
+ File.read(insertion_file).should match /Hello\s+Goodbye/
72
85
  end
73
86
 
74
87
  it "should insert Hello before Goodbye using a :content option" do
75
- File.insert_into insertion_file, :content => 'Hello ', :before => 'Goodbye'
76
- File.read(insertion_file).should_not match /Hello Goodbye/
88
+ File.insert_into insertion_file, :content => 'Hello', :before => 'Goodbye'
89
+ File.read(insertion_file).should match /Hello\s+Goodbye/
77
90
  end
78
91
 
79
92
  it "should insert Hello before Goodbye using a block as content to insert" do
80
93
  File.insert_into insertion_file, :before => 'Goodbye' do
81
- 'Hello '
94
+ 'Hello'
82
95
  end
83
- File.read(insertion_file).should_not match /Hello Goodbye/
96
+ File.read(insertion_file).should match /Hello\s+Goodbye/
84
97
  end
85
98
 
86
99
  it "should insert Hello after Goodbye using a :with option and a Regexp for the after expression" do
87
100
  File.insert_into insertion_file, :content => ' Hello', :after => /Goodbye/
88
- File.read(insertion_file).should_not match /Goodbye Hello/
101
+ File.read(insertion_file).should match /Goodbye\s+Hello/
89
102
  end
90
103
  end
91
104
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
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.2.2"
8
+ s.version = "0.2.4"
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-09-04}
12
+ s.date = %q{2010-09-13}
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 = [
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 4
9
+ version: 0.2.4
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-09-04 00:00:00 +02:00
17
+ date: 2010-09-13 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency