string_processing 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e09941d33c5b30a3b4371d53fa9f0c48fcaab559
4
+ data.tar.gz: e0c21264cb851a1ad63a2516fd8fcc17bedeee65
5
+ SHA512:
6
+ metadata.gz: a4e62a0a56143ad2c1e4337fe18d9a01783123deba57ab2c32ace69a8bc1e834005e0080825506b84ed03483d49d3a857d23683db057a878f715ddb75c9b6897
7
+ data.tar.gz: 8585ecad31365928766b403c8955bf9df4296e93e38e3a3022f55e0de8350485678037ab61a63604207043c808eac65abfce3a7c77df154e175f32ddb00f0eb0
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in string_processing.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Mike Williamson
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.
@@ -0,0 +1,52 @@
1
+ # StringProcessing
2
+
3
+ This is a tiny little gem that tries to add a little structure in
4
+ moments where you are doing extensive text transformations.
5
+
6
+ Ruby has amazing string processing abilities built in but in
7
+ circumstances were many transformations are required its common to see
8
+ long chains of gsubs/splits/joins.
9
+
10
+ The goal here is to avoid that an replace it with something a little
11
+ more readable and structured.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'string_processing'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install string_processing
26
+
27
+ ## Usage
28
+
29
+ To use StringProcessing you first define a pipeline by calling
30
+ Pipeline.define.
31
+ This will return a class which will do the processing when you call the
32
+ process method.
33
+
34
+ ```ruby
35
+ FooPipeline = StringProcessing::Pipeline.define do
36
+ using proc{|x| x.map{|n| n.split('/')} }
37
+ using proc{|x| x.map(&:downcase) }
38
+ end
39
+
40
+ FooPipeline.process "HTML/CSS"
41
+ => ["html", "css"]
42
+ ```
43
+ The processing pipeline can consist of anything that responds to #call
44
+ and both accepts and returns an array.
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( http://github.com/sleepycat/string_processing/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ require "string_processing/version"
2
+
3
+ module StringProcessing
4
+ class Pipeline
5
+
6
+ def self.define
7
+ b = Proc.new
8
+ @@processors = []
9
+ class_eval(&b)
10
+
11
+ Class.new do
12
+ @@using = @@processors
13
+
14
+ def self.process *thing
15
+ @@using.each{|x| thing = x.call(thing.flatten) }
16
+ thing
17
+ end
18
+
19
+ end
20
+ end
21
+
22
+ def self.using theblock
23
+ @@processors << theblock
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module StringProcessing
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ module StringProcessing
4
+
5
+ describe Pipeline do
6
+
7
+ describe ".define" do
8
+
9
+ it "returns a new class to do the processing" do
10
+ FooPipeline = Pipeline.define{}
11
+ expect(FooPipeline.methods).to include :process
12
+ end
13
+
14
+ it "sets up a processing pipeline based a DSL" do
15
+ FooPipeline = Pipeline.define do
16
+ using proc{|x| x.map(&:downcase) }
17
+ using proc{|x| x.map(&:strip) }
18
+ end
19
+ expect(FooPipeline.process([" FOO "])).to eq ["foo"]
20
+ end
21
+
22
+ end
23
+
24
+ describe ".process" do
25
+
26
+ it "always flattens arrays" do
27
+ FooPipeline = Pipeline.define do
28
+ using proc{|x| x.map{|n| n.split('/')} }
29
+ using proc{|x| x.map(&:downcase) }
30
+ end
31
+ expect(FooPipeline.process(["HTML/CSS"])).to eq ["html", "css"]
32
+ end
33
+
34
+ it "accepts a string" do
35
+ FooPipeline = Pipeline.define do
36
+ using proc{|x| x.map{|n| n.split('/')} }
37
+ using proc{|x| x.map(&:downcase) }
38
+ end
39
+ expect(FooPipeline.process("HTML/CSS")).to eq ["html", "css"]
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ require 'pry'
2
+ require_relative '../lib/string_processing'
3
+
4
+
@@ -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 'string_processing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "string_processing"
8
+ spec.version = StringProcessing::VERSION
9
+ spec.authors = ["Mike Williamson"]
10
+ spec.email = ["mike@korora.ca"]
11
+ spec.summary = "Create a text processing pipeline."
12
+ spec.description = "A library to create text processing pipelines."
13
+ spec.homepage = "https://github.com/sleepycat/string_processing"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: string_processing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Williamson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2014-03-10 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: "1.5"
22
+ type: :development
23
+ version_requirements: *id001
24
+ - !ruby/object:Gem::Dependency
25
+ name: rake
26
+ prerelease: false
27
+ requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - &id003
30
+ - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id002
35
+ description: A library to create text processing pipelines.
36
+ email:
37
+ - mike@korora.ca
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - LICENSE.txt
48
+ - README.md
49
+ - Rakefile
50
+ - lib/string_processing.rb
51
+ - lib/string_processing/version.rb
52
+ - spec/pipeline_spec.rb
53
+ - spec/spec_helper.rb
54
+ - string_processing.gemspec
55
+ homepage: https://github.com/sleepycat/string_processing
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - *id003
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - *id003
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 2.2.2
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Create a text processing pipeline.
78
+ test_files:
79
+ - spec/pipeline_spec.rb
80
+ - spec/spec_helper.rb