epitools 0.5.23 → 0.5.24

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: eda0067cd8c9886dabdb526424d410352bce1608
4
- data.tar.gz: 9bd399762f667a7926582901f9697b8e0a0d3f8e
3
+ metadata.gz: 805cba0468e349409afa128ad90315a71af8439b
4
+ data.tar.gz: 8ac5bad550b8b4cf60eab00d8fd724fb265c7f88
5
5
  SHA512:
6
- metadata.gz: 7ccbed66625408ddc19bb3715f4e346dea77a45f07aba06fa6b7da4d7b5d2c444b1765c63469875856545c06ed6262acc87e22db8cc5f43789a01e5f392126bb
7
- data.tar.gz: d07f39021df1b1d30900ad6e6bde8b0c8f0803875de9395baaa86babac2b749a7436bde521fb90683198bb9e95a849f36d0573a886704e830b133200716a0d6a
6
+ metadata.gz: c87ddb780950cf09a9f8f1c788180a932d0bdcafea11b2549d49f5ca1371d597f275f7368508228f6380d08aeaa08ea8617877b349cbbf385fa66ca0fd63c481
7
+ data.tar.gz: 72c908c9b6de89c1a63950d975aed01909759d8505b6eee983e6aaa91b3277d4c8bd65226fe931ff760e248cf4f345850d08afb176fe38cb190e924305990544
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.23
1
+ 0.5.24
@@ -84,6 +84,36 @@ class String
84
84
  alias_method :nicelines, :nice_lines
85
85
  alias_method :clean_lines, :nice_lines
86
86
 
87
+ #
88
+ # Wrap the lines in the string so they're at most "width" wide.
89
+ # (If no width is specified, defaults to the width of the terminal.)
90
+ #
91
+ def wrap(width=nil, ignore=nil)
92
+ if width.nil?
93
+ require 'io/console'
94
+ height, width = STDIN.winsize
95
+ end
96
+
97
+ wrap_re = /(?:.{1,#{width}}[ \t]+|.{1,#{width}})/
98
+
99
+ # TODO: 'ignore' ignores characters matching some regexp
100
+ #
101
+ # if ignore
102
+ # stripped = gsub(ignore, '') # remove whatever we're ignoring
103
+ # lines = stripped.scan(wrap_re) # wrap the lines
104
+ # lines.each do |line|
105
+ # line.
106
+ # end
107
+
108
+ scan(wrap_re).map(&:rstrip).join("\n")
109
+ end
110
+
111
+ #
112
+ # Indent all the lines in the string by "amount" of spaces.
113
+ #
114
+ def indent(amount=2)
115
+ lines.map { |line| (" "*amount) + line }.join ''
116
+ end
87
117
 
88
118
  #
89
119
  # Iterate over slices of the string of size `slice_width`.
@@ -504,10 +504,12 @@ class Path
504
504
  read_json
505
505
  when 'html', 'htm'
506
506
  read_html
507
- when 'xml', 'rdf', 'rss'
508
- read_xml
509
507
  when 'yaml', 'yml'
510
508
  read_yaml
509
+ when 'xml', 'rdf', 'rss'
510
+ read_xml
511
+ when 'csv'
512
+ read_csv
511
513
  when 'marshal'
512
514
  read_marshal
513
515
  when 'bson'
@@ -546,6 +548,12 @@ class Path
546
548
  end
547
549
  alias_method :from_yaml, :read_yaml
548
550
 
551
+ # Parse the file as CSV
552
+ def read_csv(opts={})
553
+ CSV.open(io, opts).each
554
+ end
555
+ alias_method :from_csv, :read_csv
556
+
549
557
 
550
558
  def read_xml
551
559
  Nokogiri::XML(io)
@@ -186,6 +186,18 @@ describe String do
186
186
  "\n\n\nblah\n\n\nblah\n\n\n".nice_lines.should == ["blah", "blah"]
187
187
  end
188
188
 
189
+ it "wraps" do
190
+ s1 = "Hello there, I am a sentence or series of words."
191
+ s2 = "012345678901234567890123456789012345678901234567"
192
+ s1.wrap(14).should == "Hello there, I\nam a sentence\nor series of\nwords."
193
+ s2.wrap(14).should == "01234567890123\n45678901234567\n89012345678901\n234567"
194
+ end
195
+
196
+ it "indents" do
197
+ s = "Some things\nNeed indenting\nSo, you indent them!\n"
198
+ s.indent(2).should == " Some things\n Need indenting\n So, you indent them!\n"
199
+ end
200
+
189
201
  it "titlecases" do
190
202
  "asdf asdfasdf asdf".titlecase.should == "Asdf Asdfasdf Asdf"
191
203
  " asdf".titlecase.should == " Asdf"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.23
4
+ version: 0.5.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-27 00:00:00.000000000 Z
11
+ date: 2013-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -127,3 +127,4 @@ signing_key:
127
127
  specification_version: 3
128
128
  summary: Not utils... METILS!
129
129
  test_files: []
130
+ has_rdoc: