excise 0.1.0

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.
data/.gitignore ADDED
@@ -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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'guard-rspec'
7
+ gem 'rb-fsevent', require: false
8
+ gem 'rake', '10.0.0.beta1'
9
+ end
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec', cli: '--format=progress' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ezekiel Templin
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,37 @@
1
+ # Excise [![Build Status](https://secure.travis-ci.org/ezkl/excise.png)](http://travis-ci.org/ezkl/excise)
2
+ > This is a simple helper to extract values from a string based on a pattern.
3
+
4
+ A Ruby port of [laktek's](https://github.com/laktek/) [extract-values](https://github.com/laktek/extract-values).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'excise'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install excise
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ require 'excise'
24
+
25
+ Excise.parse('About 49,000,000 results (0.15 seconds)',
26
+ 'About {result_count} results ({load_time} seconds)')
27
+
28
+ #=> {:result_count=>"49,000,000", :load_time=>"0.15"}
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/excise.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'excise/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "excise"
8
+ gem.version = Excise::VERSION
9
+ gem.authors = ["Ezekiel Templin"]
10
+ gem.email = ["zeke@templ.in"]
11
+ gem.description = %q{Excise is a Ruby port of extract-values}
12
+ gem.summary = %q{From extract-values description: "... a simple helper to extract values from a string based on a pattern."}
13
+ gem.homepage = "http://zeke.templ.in/excise"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = gem.files.grep('spec')
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_development_dependency 'rspec', '~> 2.11.0'
20
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ module Excise
4
+ class Base
5
+ def initialize(string, pattern)
6
+ @string = string
7
+ @pattern = pattern
8
+ @matches = pattern_expression.match(@string)
9
+ @output = {}
10
+ end
11
+
12
+ def parse
13
+ tokens.each_with_index do |key, index|
14
+ @output[key.to_sym] = @matches[index+1]
15
+ end
16
+ @output
17
+ end
18
+
19
+ def tokens
20
+ @pattern.scan(token_expression).flatten
21
+ end
22
+
23
+ def pattern_expression
24
+ Regexp.new(@pattern.gsub(special_characters_expression, '\\\\\0').gsub(token_expression, "(\.+)"))
25
+ end
26
+
27
+ def token_expression
28
+ /{([^{}\t\r\n]+)}/
29
+ end
30
+
31
+ def special_characters_expression
32
+ /[\\\^\$\*\+\.\?\(\)\[\]]/
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Excise
2
+ VERSION = "0.1.0"
3
+ end
data/lib/excise.rb ADDED
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ require "excise/version"
3
+ require "excise/base"
4
+
5
+ module Excise
6
+ def self.parse(string, pattern)
7
+ Base.new(string, pattern).parse
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ module Excise
4
+ describe "Base" do
5
+ context 'patterned string' do
6
+ subject { Base.new(string, pattern).parse }
7
+
8
+ let(:string) { '[this] (patterned) <STRING>' }
9
+ let(:pattern) { '[{first}] ({second}) <{third}>' }
10
+
11
+ it { should be_a Hash }
12
+ its(:keys) { should eq [:first, :second, :third] }
13
+ its(:values) { should eq ['this', 'patterned', 'STRING'] }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Excise do
4
+ describe ".parse" do
5
+ subject { Excise.parse(string, pattern) }
6
+
7
+ let(:string) { '[this] (patterned) <STRING>' }
8
+ let(:pattern) { '[{first}] ({second}) <{third}>' }
9
+
10
+ it { should be_a Hash }
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require './lib/excise'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+
8
+ config.order = 'random'
9
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: excise
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ezekiel Templin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.11.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.11.0
30
+ description: Excise is a Ruby port of extract-values
31
+ email:
32
+ - zeke@templ.in
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rspec
39
+ - .travis.yml
40
+ - Gemfile
41
+ - Guardfile
42
+ - LICENSE.txt
43
+ - README.md
44
+ - Rakefile
45
+ - excise.gemspec
46
+ - lib/excise.rb
47
+ - lib/excise/base.rb
48
+ - lib/excise/version.rb
49
+ - spec/excise/base_spec.rb
50
+ - spec/excise_spec.rb
51
+ - spec/spec_helper.rb
52
+ homepage: http://zeke.templ.in/excise
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.23
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: ! 'From extract-values description: "... a simple helper to extract values
76
+ from a string based on a pattern."'
77
+ test_files: []
78
+ has_rdoc: