ChunkyText 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c2e90bc4405aad6565a25ffede0b8850be4118cf
4
+ data.tar.gz: e226157c071bc84131b332e858579c1b5f1d484c
5
+ SHA512:
6
+ metadata.gz: 43c849dd97370417af2a6c2a734335bf93359fb9b830564a06e53796458a4d58f9e2228f99bb590037ed10bf0786e5c825c46ad10ce03737d62f1fb7fa0edf14
7
+ data.tar.gz: 046c045899c47714c0b24501956c860687d47eace0224932b898abcd1000c1003b805fea3bf15c2dacb53683ac56eadd75f52d4686512ed0b171cfc105f973c5
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - ruby
6
+ - 2.1.5
7
+
8
+ script: 'bundle exec rake'
9
+
10
+ notifications:
11
+ email:
12
+ recipients:
13
+ - dstein-phins@hotmail.com
14
+ on_failure: change
15
+ on_success: never
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ChunkyText/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ChunkyText"
7
+ spec.version = ChunkyText::VERSION
8
+ spec.authors = ["Doug Steinberg", "Jason Parker"]
9
+ spec.email = ["dstein-phins@hotmail.com"]
10
+ spec.summary = %q{ Break up a long string of text into smaller strings for Twitter }
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 = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "guard"
24
+ spec.add_development_dependency "guard-rspec"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "pry-remote"
27
+ spec.add_development_dependency "pry-nav"
28
+ spec.add_development_dependency "coveralls"
29
+ spec.add_development_dependency "faker"
30
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ChunkyText.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ guard :rspec, cmd: 'rspec' do
2
+ # watch /lib/ files
3
+ watch(%r{^lib/(.+).rb$}) do |m|
4
+ "spec/#{m[1]}_spec.rb"
5
+ end
6
+
7
+ # watch /spec/ files
8
+ watch(%r{^spec/(.+).rb$}) do |m|
9
+ "spec/#{m[1]}.rb"
10
+ end
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Doug Steinberg
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ [![Build Status](https://travis-ci.org/Integralist/Sinderella.png?branch=master)](https://travis-ci.org/Integralist/Sinderella) [![Gem Version](https://badge.fury.io/rb/sinderella.png)](http://badge.fury.io/rb/sinderella) [![Coverage Status](https://coveralls.io/repos/Integralist/Sinderella/badge.png)](https://coveralls.io/r/Integralist/Sinderella)
2
+
3
+ # ChunkyText
4
+
5
+ TODO: Write a gem description
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ChunkyText'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ChunkyText
22
+
23
+ ## Usage
24
+
25
+ You have a given string. Example:
26
+
27
+ string = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
28
+
29
+ Initialize the ChunkyText object with the string and a max length
30
+
31
+ text = ChunkyText::Chunker.new(string, 140)
32
+
33
+ Call `.chunk_array` on the object and get an array back.
34
+
35
+ ```ruby
36
+ text.chunk_array #=> ["Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, ... , ... , ...]
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( https://github.com/[my-github-username]/ChunkyText/fork )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color', '--format', 'nested']
8
+ end
9
+
10
+ task :default => :spec
data/lib/ChunkyText.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "ChunkyText/version"
2
+ require "ChunkyText/chunker"
3
+
4
+
5
+
6
+
7
+ #
8
+ # get the first 140 characters
9
+ # find the location of the last punctuation mark
10
+ # save all characters from that puncuation mark to the beging of the string to a variable
11
+ # save that variable to the end of a "chunks" array
12
+ # remove the characters from the input string
13
+ # repeat the process untill the input string is empty
14
+ # return the "chunks" array
15
+ #
16
+ # if any neighboring elements in the array add up to 140 chars or less, then merge them together
@@ -0,0 +1,45 @@
1
+ module ChunkyText
2
+ class Chunker
3
+
4
+ attr_reader :max_length, :chunk_array, :get_chunk
5
+ attr_accessor :string
6
+
7
+ def initialize(string, max_length)
8
+ @string = string
9
+ @max_length = max_length
10
+ end
11
+
12
+ def get_chunk(input_string)
13
+ smaller_string = input_string.slice(0,max_length)
14
+
15
+ if last_punctuation_mark(smaller_string)
16
+ smaller_string.slice(0,last_punctuation_mark(smaller_string) + 1)
17
+ else
18
+ smaller_string
19
+ end
20
+ end
21
+
22
+ def chunk_array
23
+ input_string = string.clone
24
+ array = []
25
+ while input_string.length > 0 do
26
+ array << get_chunk(input_string)
27
+
28
+ input_string.slice!(0..max_length)
29
+ end
30
+ input_string = string.clone
31
+ array
32
+ end
33
+
34
+ private
35
+
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
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module ChunkyText
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe ChunkyText::Chunker do
4
+ let(:punctuation_mark) { ['!','?','.'].sample }
5
+ let(:long_text) { Faker::Lorem.paragraph(30) }
6
+
7
+ let(:string_with_punctuation_before_140_chars) do
8
+ string = Faker::Lorem.characters(130)
9
+ string + punctuation_mark + string
10
+ end
11
+
12
+ let(:string_with_punctuation_at_140_chars) do
13
+ string = Faker::Lorem.characters(139)
14
+ string + punctuation_mark
15
+ end
16
+
17
+ let(:string_with_no_punctuation_before_140_chars) do
18
+ string = Faker::Lorem.characters(150)
19
+ end
20
+
21
+ describe '#get_chunk' do
22
+ it '[returns a string]' do
23
+ text = ChunkyText::Chunker.new(long_text, 140)
24
+ expect(text.get_chunk(text.string)).to be_a(String)
25
+ end
26
+
27
+ it '[returns a string <= the max length]' do
28
+ text = ChunkyText::Chunker.new(long_text, 140)
29
+ expect(text.get_chunk(text.string).length).to be <= 140
30
+ end
31
+
32
+
33
+ context '[a punctuation mark occurs before the max length character]' do
34
+ it '[returns a string < the max length]' do
35
+ text = ChunkyText::Chunker.new(string_with_punctuation_before_140_chars, 140)
36
+ expect(text.get_chunk(text.string).length).to be < 140
37
+ end
38
+
39
+ it '[returns a string that ends in a punctuation mark]' do
40
+ text = ChunkyText::Chunker.new(long_text, 140)
41
+ expect(['!','?','.']).to include(text.get_chunk(text.string)[-1])
42
+ end
43
+ end
44
+
45
+ context '[a punctuation mark occurs at the max length character]' do
46
+ it '[returns a string == the max length]' do
47
+ text = ChunkyText::Chunker.new(string_with_punctuation_at_140_chars, 140)
48
+ expect(text.get_chunk(text.string).length).to eq(140)
49
+ end
50
+ end
51
+
52
+ context '[there is no punctuation mark within the max length]' do
53
+ it '[returns a string == the max length]' do
54
+ text = ChunkyText::Chunker.new(string_with_no_punctuation_before_140_chars, 140)
55
+ expect(text.get_chunk(text.string).length).to eq(140)
56
+ end
57
+ end
58
+
59
+
60
+ end
61
+
62
+ describe '#chunk_array' do
63
+ it '[returns an array]' do
64
+ array = ChunkyText::Chunker.new(long_text, 140).chunk_array
65
+ expect(array).to be_a(Array)
66
+ end
67
+
68
+ it '[each element in the array is a string]' do
69
+ array = ChunkyText::Chunker.new(long_text, 140).chunk_array
70
+ array.each do |elem|
71
+ expect(elem).to be_a(String)
72
+ end
73
+ end
74
+
75
+ it '[each element is <= the max_length]' do
76
+ array = ChunkyText::Chunker.new(long_text, 140).chunk_array
77
+ array.each do |elem|
78
+ expect(elem.length).to be <= 140
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'pry'
5
+ require 'faker'
6
+ require 'ChunkyText'
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ChunkyText
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Doug Steinberg
8
+ - Jason Parker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: guard
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: guard-rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry-remote
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: pry-nav
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: coveralls
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: faker
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ description: " Break up a long string of text into nicely formated 140 character strings
155
+ for Twitter and keping links and punctuation intact. "
156
+ email:
157
+ - dstein-phins@hotmail.com
158
+ executables: []
159
+ extensions: []
160
+ extra_rdoc_files: []
161
+ files:
162
+ - ".coveralls.yml"
163
+ - ".gitignore"
164
+ - ".rspec"
165
+ - ".travis.yml"
166
+ - ChunkyText.gemspec
167
+ - Gemfile
168
+ - Guardfile
169
+ - LICENSE.txt
170
+ - README.md
171
+ - Rakefile
172
+ - lib/ChunkyText.rb
173
+ - lib/ChunkyText/chunker.rb
174
+ - lib/ChunkyText/version.rb
175
+ - spec/models/chunker_spec.rb
176
+ - spec/spec_helper.rb
177
+ homepage: ''
178
+ licenses:
179
+ - MIT
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.4.3
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Break up a long string of text into smaller strings for Twitter
201
+ test_files:
202
+ - spec/models/chunker_spec.rb
203
+ - spec/spec_helper.rb