clean-cut 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/clean-cut +4 -0
  3. data/lib/clean-cut.rb +44 -0
  4. metadata +49 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e9ae00e1a02a2e0eb1fa9e3cab553611d3dac6fe
4
+ data.tar.gz: eaec78cfcfab9cfc45d1f6ca763eae80747e73a4
5
+ SHA512:
6
+ metadata.gz: 93b2c1121364972ebd8085dd87c8486acd5ea3eda17e1a733d9be8e3656ab9df81277ffae35bb8839062feb5582fe8884a5f0ba25e879c33c7b4a419fc75e864
7
+ data.tar.gz: e312cf732ce1a4514a4cfeaaed1c44bed3ad91a3760062727e07aaceeb9c5a8d8ffeb0fb57e9daa741526c05e1d84470419421ce5084fc2321c01e2fc14db3ab
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'clean-cut'
4
+ CleanCut.cut(string_to_cut: ARGV[0], character_limit: ARGV[1])
@@ -0,0 +1,44 @@
1
+ class CleanCut
2
+ class << self
3
+
4
+ DEFAULT_Options = {
5
+ :string_to_cut => "",
6
+ :character_limit => nil
7
+ }
8
+
9
+ def cut(user_options={})
10
+ options = DEFAULT_Options.merge(user_options)
11
+
12
+ @string_to_cut = options[:string_to_cut]
13
+ @character_limit = options[:character_limit]
14
+
15
+ raise "character limit must be >= 0." if @character_limit == nil
16
+ raise "string must have a length >= 1" if @string_to_cut.length < 1
17
+
18
+ cut_index = find_clean(@string_to_cut, @character_limit)
19
+
20
+ if cut_index == 0
21
+ first_part = ""
22
+ second_part = @string_to_cut[(cut_index..@string_to_cut.length - 1)]
23
+ elsif cut_index > 0
24
+ first_part = @string_to_cut[(0..cut_index)].chomp " "
25
+ second_part = @string_to_cut[(cut_index + 1..@string_to_cut.length - 1)]
26
+ end
27
+
28
+ [first_part, second_part].map do |string|
29
+ if string == nil
30
+ string = ""
31
+ else
32
+ string = string
33
+ end
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def find_clean(string, limit)
40
+ return limit if limit == 0 || !string[limit] || string[limit] == " "
41
+ find_clean(string, limit-= 1)
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clean-cut
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jadzia Thomas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Specify a character limit and a string. Returns an array with the first
14
+ and second parts of the original string as two new strings without splitting any
15
+ words.
16
+ email: "<email hidden>"
17
+ executables:
18
+ - clean-cut
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/clean-cut
23
+ - lib/clean-cut.rb
24
+ homepage: http://rubygems.org/gems/clean-cut
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.4.5
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: A simple gem that cuts a string at a character limit without spliting any
48
+ word that is not fully inside the character limit.
49
+ test_files: []