ChunkyText 0.0.1 → 0.0.2

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: c2e90bc4405aad6565a25ffede0b8850be4118cf
4
- data.tar.gz: e226157c071bc84131b332e858579c1b5f1d484c
3
+ metadata.gz: 491751797404fbf89fd57a908084dfd07c07ca40
4
+ data.tar.gz: 93fbb2e831ed4f4a5b3b9c32db592466cd367133
5
5
  SHA512:
6
- metadata.gz: 43c849dd97370417af2a6c2a734335bf93359fb9b830564a06e53796458a4d58f9e2228f99bb590037ed10bf0786e5c825c46ad10ce03737d62f1fb7fa0edf14
7
- data.tar.gz: 046c045899c47714c0b24501956c860687d47eace0224932b898abcd1000c1003b805fea3bf15c2dacb53683ac56eadd75f52d4686512ed0b171cfc105f973c5
6
+ metadata.gz: be92f5171bb05a232142743dde631e63052c508e6213135368c6e417b880d55c6114390b235d90a0f7f0db327ab31108456f5fd7b60166ea39c86d04963281c2
7
+ data.tar.gz: 14242f1502ade16e1c751994f7cc42bd69a929d1e64e260c415a9f7e025822be8f533b0814a78cd3c0d30fa3eb68943087c0f8091c03e1a3ccfca0c95222e35b
Binary file
data/ChunkyText.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["dstein-phins@hotmail.com"]
10
10
  spec.summary = %q{ Break up a long string of text into smaller strings for Twitter }
11
11
  spec.description = %q{ Break up a long string of text into nicely formated 140 character strings for Twitter and keping links and punctuation intact. }
12
- spec.homepage = ""
12
+ spec.homepage = "https://github.com/ZestySalsa/ChunkyText"
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
@@ -1,19 +1,22 @@
1
1
  module ChunkyText
2
2
  class Chunker
3
+
4
+ PREPEND_COUNT = 6
3
5
 
4
- attr_reader :max_length, :chunk_array, :get_chunk
6
+ attr_reader :max_length, :chunk_array, :get_chunk, :elipse
5
7
  attr_accessor :string
6
8
 
7
- def initialize(string, max_length)
9
+ def initialize(string, max_length, elipse = "(...)")
8
10
  @string = string
9
- @max_length = max_length
11
+ @elipse = elipse
12
+ @max_length = max_length - elipse.length - 1
10
13
  end
11
14
 
12
- def get_chunk(input_string)
13
- smaller_string = input_string.slice(0,max_length)
15
+ def get_chunk(input_string)
16
+ smaller_string = input_string.slice(0,max_length - PREPEND_COUNT)
14
17
 
15
- if last_punctuation_mark(smaller_string)
16
- smaller_string.slice(0,last_punctuation_mark(smaller_string) + 1)
18
+ if last_space(smaller_string)
19
+ smaller_string.slice(0,last_space(smaller_string) + 1)
17
20
  else
18
21
  smaller_string
19
22
  end
@@ -23,23 +26,26 @@ module ChunkyText
23
26
  input_string = string.clone
24
27
  array = []
25
28
  while input_string.length > 0 do
26
- array << get_chunk(input_string)
27
-
28
- input_string.slice!(0..max_length)
29
+ if input_string.length > max_length - PREPEND_COUNT
30
+ chunk = get_chunk(input_string)
31
+ array << chunk + ' ' + elipse
32
+ input_string.slice!(0..chunk.length - 1)
33
+ else
34
+ array << input_string
35
+ break
36
+ end
29
37
  end
30
38
  input_string = string.clone
31
- array
39
+
40
+ array.map!.with_index do |chunk, i|
41
+ "(#{i + 1}/#{array.count}) " + chunk
42
+ end
32
43
  end
33
44
 
34
45
  private
35
46
 
36
- def last_punctuation_mark(string)
37
- punctuation_mark_positions = []
38
- ['!','?','.'].each do |p_mark|
39
- punctuation_mark_positions << string.rindex(p_mark)
40
- end
41
- punctuation_mark_positions.reject! { |item| item == nil }
42
- punctuation_mark_positions.max
47
+ def last_space(string)
48
+ position = string.rindex /\s/
43
49
  end
44
50
  end
45
51
  end
@@ -1,3 +1,3 @@
1
1
  module ChunkyText
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ChunkyText
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Steinberg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-14 00:00:00.000000000 Z
12
+ date: 2015-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -163,6 +163,7 @@ files:
163
163
  - ".gitignore"
164
164
  - ".rspec"
165
165
  - ".travis.yml"
166
+ - ChunkyText-0.0.1.gem
166
167
  - ChunkyText.gemspec
167
168
  - Gemfile
168
169
  - Guardfile
@@ -174,7 +175,7 @@ files:
174
175
  - lib/ChunkyText/version.rb
175
176
  - spec/models/chunker_spec.rb
176
177
  - spec/spec_helper.rb
177
- homepage: ''
178
+ homepage: https://github.com/ZestySalsa/ChunkyText
178
179
  licenses:
179
180
  - MIT
180
181
  metadata: {}