counter_string 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9ec947ddc8f790923f9e86e957e8e0c31f5af58
4
+ data.tar.gz: 20351d01037167b2f3589cfb05656170a5a72e8b
5
+ SHA512:
6
+ metadata.gz: e65774c06798aab74e015ef99af104962c3315b607104db76c05500ef4ead4b6429181e1375aab1d33a7ceaa15d0cc704bc7a3445c438d53486b8886105b96f2
7
+ data.tar.gz: 229e364e59873731fd4dd1412df2ded10b4a3ac5f39368b8618cfdcdb0f3bbd577b50556a6fc811ff5e039b12004fbf956a316b67018809101450bb1a88adf6f
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .ruby-*
3
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in inline_svg.gemspec
4
+ gemspec
@@ -0,0 +1,18 @@
1
+ Counter strings are self documenting strings with respect to their length. CounterString is a class that creates counter strings of arbitrary length.
2
+
3
+ James Bach, [describes counter strings](http://www.satisfice.com/blog/archives/22) as follows:
4
+
5
+ "A counterstring is a graduated string of arbitrary length. No matter where you are in the string, you always know the character position. This comes in handy when you are pasting huge strings into fields and they get truncated at a certain point. You want to know how many characters that is."
6
+
7
+ Here's a simple example of its use:
8
+
9
+ ```ruby
10
+ require 'rubygems'
11
+ require 'counter_string'
12
+
13
+ cs = CounterString.new
14
+
15
+ p cs.generate 35
16
+
17
+ => "2*4*6*8*11*14*17*20*23*26*29*32*35*"
18
+ ```
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "counter_string"
8
+ s.version = VERSION
9
+ s.author = "James Martin"
10
+ s.email = "counterstring@jmrtn.com"
11
+ s.homepage = "http://github.com/jamesmartin/counterstring"
12
+ s.platform = Gem::Platform::RUBY
13
+ s.summary = "A class for generating self documenting strings"
14
+ s.description = "Counter strings are self documenting strings with respect to their length. This class will create counter strings of arbitrary length."
15
+ s.files = `git ls-files`.split($/)
16
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "bundler", "~> 1.5"
21
+ s.add_development_dependency "rake"
22
+ s.add_development_dependency "rspec", "~> 3.2"
23
+ end
@@ -0,0 +1,32 @@
1
+ class CounterString
2
+ def initialize()
3
+ @position_marker_character = "*"
4
+ @output = ""
5
+ end
6
+
7
+ def generate(length=0)
8
+ if length == 0
9
+ return ""
10
+ elsif length == 1
11
+ return "#{length}"
12
+ else
13
+ @output = "2" + @position_marker_character
14
+ last_position_number = 2
15
+ while @output.size < length
16
+ position_number = @output.size + (last_position_number.to_s.size + 1)
17
+ if position_number.to_s.size > last_position_number.to_s.size
18
+ position_number += 1
19
+ end
20
+ token = position_number.to_s + @position_marker_character
21
+ remaining_length = length - @output.size
22
+ if remaining_length < token.size + @output.size
23
+ token = token[0,remaining_length]
24
+ end
25
+ @output += token
26
+ last_position_number = position_number
27
+ end
28
+ end
29
+ return @output
30
+ end
31
+
32
+ end
@@ -0,0 +1 @@
1
+ VERSION = '0.1.0'
@@ -0,0 +1,42 @@
1
+ require_relative '../lib/counter_string'
2
+
3
+ describe CounterString do
4
+ before(:each) do
5
+ @cs = CounterString.new
6
+ end
7
+ it "returns blank for no arguments" do
8
+ @cs.generate.should == ""
9
+ end
10
+
11
+ it "returns 1 for length 1" do
12
+ @cs.generate(1).should == "1"
13
+ end
14
+
15
+ it "returns 2* for length 2" do
16
+ @cs.generate(2).should == "2*"
17
+ end
18
+
19
+ it "returns 2*4 for length 3" do
20
+ @cs.generate(3).should == "2*4"
21
+ end
22
+
23
+ it "returns 2*4*6*8*1 for length 9" do
24
+ @cs.generate(9).should == "2*4*6*8*1"
25
+ end
26
+
27
+ it "returns 2*4*6*8*11* for length 11" do
28
+ @cs.generate(11).should == "2*4*6*8*11*"
29
+ end
30
+
31
+ it "returns 2*4..10 for length 100" do
32
+ string = @cs.generate(100)
33
+ string.size.should == 100
34
+ string[96,99].should == "8*10"
35
+ end
36
+
37
+ it "returns 2*4...2048 for length 2047" do
38
+ string = @cs.generate(2047)
39
+ string.size.should == 2047
40
+ string[2039,2046].should == "043*2048"
41
+ end
42
+ end
@@ -0,0 +1 @@
1
+ --color
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: counter_string
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Martin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: Counter strings are self documenting strings with respect to their length.
56
+ This class will create counter strings of arbitrary length.
57
+ email: counterstring@jmrtn.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - counterstring.gemspec
67
+ - lib/counter_string.rb
68
+ - lib/version.rb
69
+ - spec/counter_string_spec.rb
70
+ - spec/spec.opts
71
+ homepage: http://github.com/jamesmartin/counterstring
72
+ licenses: []
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.7
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: A class for generating self documenting strings
94
+ test_files:
95
+ - spec/counter_string_spec.rb
96
+ - spec/spec.opts