llt-core_extensions 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: 8b1a6adc727502947dc4bb4e2195cffb84ccd156
4
+ data.tar.gz: 904cccbc8e337f15e7d22126fdb07c95784a09c0
5
+ SHA512:
6
+ metadata.gz: 607f1593c2d66a28d42986539f1b02861cc9d0f91710257a5c220b441dcef066947b763c3c5c84d66d3ae6f1fe742d15bed59d242c338661c38746a4f0425752
7
+ data.tar.gz: e46da062a13919daa0eb125d48c44d2e1c1006aa91c87e8f7e69727bc91c71d06fb06afc9a1e5b9fba136f03d3d0daed7d04ebff45f2c012587cbf088d14eaa1
@@ -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,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in llt-core_extensions.gemspec
4
+ gemspec
5
+ gem 'coveralls', require: false
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 LFDM
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,29 @@
1
+ # LLT::CoreExtensions
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'llt-core_extensions'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install llt-core_extensions
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = '-f d --color --tty'
6
+ end
7
+
8
+ task :default => :spec
@@ -0,0 +1,11 @@
1
+ require "llt/core_extensions/version"
2
+
3
+ module LLT
4
+ module CoreExtensions
5
+ require "llt/core_extensions/enumerable"
6
+ require "llt/core_extensions/array"
7
+ require "llt/core_extensions/match_data"
8
+ require "llt/core_extensions/object"
9
+ require "llt/core_extensions/symbol"
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module LLT
2
+ module CoreExtensions
3
+ module Array
4
+ def select_indices
5
+ indices = []
6
+ each_with_index { |x, i| indices << i if yield(x) }
7
+ indices
8
+ end
9
+
10
+ def each_overlapping_pair
11
+ pairs = self[0..-2].zip(self[1..-1])
12
+ if block_given?
13
+ pairs.each { |pair| yield(pair) }
14
+ else
15
+ pairs.to_enum
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ class Array
23
+ include LLT::CoreExtensions::Array
24
+ # Enumerable needs to be included again after it includes
25
+ # a module itself. Strange...
26
+ include Enumerable
27
+ end
@@ -0,0 +1,17 @@
1
+ module LLT
2
+ module CoreExtensions
3
+ module Enumerable
4
+ def each_with_index_and_object(arg, &blk)
5
+ each_with_index.each_with_object(arg, &blk)
6
+ end
7
+
8
+ def map_with_index(&blk)
9
+ each_with_index.map(&blk)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ module Enumerable
16
+ include LLT::CoreExtensions::Enumerable
17
+ end
@@ -0,0 +1,13 @@
1
+ module LLT
2
+ module CoreExtensions
3
+ module MatchData
4
+ def to_hash
5
+ Hash[ names.map(&:to_sym).zip(captures) ]
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ class MatchData
12
+ include LLT::CoreExtensions::MatchData
13
+ end
@@ -0,0 +1,15 @@
1
+ require 'llt/core_extensions/symbol'
2
+
3
+ module LLT
4
+ module CoreExtensions
5
+ module Object
6
+ def query(message)
7
+ send(message.to_query)
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ class Object
14
+ include LLT::CoreExtensions::Object
15
+ end
@@ -0,0 +1,13 @@
1
+ module LLT
2
+ module CoreExtensions
3
+ module Symbol
4
+ def to_query
5
+ "#{self}?".to_sym
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ class Symbol
12
+ include LLT::CoreExtensions::Symbol
13
+ end
@@ -0,0 +1,5 @@
1
+ module LLT
2
+ module CoreExtensions
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'llt/core_extensions/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "llt-core_extensions"
8
+ spec.version = LLT::CoreExtensions::VERSION
9
+ spec.authors = ["LFDM"]
10
+ spec.email = ["1986gh@gmail.com"]
11
+ spec.description = %q{LLT Core Extensions}
12
+ spec.summary = %q{LLT Core Extensions}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "simplecov", "~> 0.7"
25
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Array do
4
+ describe "#select_indices" do
5
+ it "select the indices of array elements for which the block is true" do
6
+ %i{ a b c a b c}.select_indices { |x| x == :a }.should == [0, 3]
7
+ end
8
+
9
+ it "has flexible arity" do
10
+ [[1,2]].select_indices { |x,y| x == 1 && y == 2 }.should have(1).item
11
+ end
12
+ end
13
+
14
+ describe "#each_overlapping_pair" do
15
+ it "returns an enumerator for each overlapping pair" do
16
+ overlapped_pairs = %w{ a b c }.each_overlapping_pair.map do |pair|
17
+ pair.map(&:upcase)
18
+ end
19
+ overlapped_pairs.should == [%w{ A B }, %w{ B C }]
20
+ end
21
+
22
+ it "has biarity as well" do
23
+ overlapped_pairs = %w{ a b c }.each_overlapping_pair.map do |a, b|
24
+ [a.upcase, b]
25
+ end
26
+ overlapped_pairs.should == [%w{ A b }, %w{ B c }]
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Enumerable do
4
+ describe "#each_with_index_and_object" do
5
+ it "is a shortcut for each_with_index.each_with_object" do
6
+ %i{ a b }.each_with_index_and_object({}) do |(e, i), h|
7
+ h[e] = i
8
+ end.should == { a: 0, b: 1 }
9
+ end
10
+ end
11
+
12
+ describe "#map_with_index" do
13
+ it "is a shortcut for each_with_index.map" do
14
+ [100, 200].map_with_index do |e, i|
15
+ e * i
16
+ end.should == [0, 200]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe MatchData do
4
+ describe "#to_hash" do
5
+ it "returns a hash with key name.to_sym and value capture" do
6
+ m = "alloa_ruby".match(/(?<hello>all).*(?<lang>ruby)/)
7
+ m.to_hash.should == { hello: "all", lang: "ruby" }
8
+ end
9
+
10
+ it "returns an empty hash when there are no named captures present" do
11
+ m = "nothing here".match(/nothing/)
12
+ m.to_hash.should == {}
13
+
14
+ m = "nothing here".match(/(nothing)/)
15
+ m.to_hash.should == {}
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Object do
4
+ describe "#query" do
5
+ it "sends a message in query format using Symbol#to_query" do
6
+ x = double
7
+ x.should_receive(:test?)
8
+ x.should_not receive(:test)
9
+
10
+ x.query(:test)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Symbol do
4
+ describe "#to_query" do
5
+ it "adds a question mark - query method style - to a symbol" do
6
+ :test.to_query.should == :test?
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ Coveralls.wear!
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+
11
+ SimpleCov.start do
12
+ add_filter '/spec/'
13
+ end
14
+
15
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
16
+ require 'llt/core_extensions'
17
+
18
+ RSpec.configure do |config|
19
+ config.treat_symbols_as_metadata_keys_with_true_values = true
20
+ config.run_all_when_everything_filtered = true
21
+ config.filter_run :focus
22
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: llt-core_extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - LFDM
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-08 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ description: LLT Core Extensions
70
+ email:
71
+ - 1986gh@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/llt/core_extensions.rb
82
+ - lib/llt/core_extensions/array.rb
83
+ - lib/llt/core_extensions/enumerable.rb
84
+ - lib/llt/core_extensions/match_data.rb
85
+ - lib/llt/core_extensions/object.rb
86
+ - lib/llt/core_extensions/symbol.rb
87
+ - lib/llt/core_extensions/version.rb
88
+ - llt-core_extensions.gemspec
89
+ - spec/lib/llt/core_extensions/array_spec.rb
90
+ - spec/lib/llt/core_extensions/enumerable_spec.rb
91
+ - spec/lib/llt/core_extensions/match_data_spec.rb
92
+ - spec/lib/llt/core_extensions/object_spec.rb
93
+ - spec/lib/llt/core_extensions/symbol_spec.rb
94
+ - spec/spec_helper.rb
95
+ homepage: ''
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.1.5
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: LLT Core Extensions
119
+ test_files:
120
+ - spec/lib/llt/core_extensions/array_spec.rb
121
+ - spec/lib/llt/core_extensions/enumerable_spec.rb
122
+ - spec/lib/llt/core_extensions/match_data_spec.rb
123
+ - spec/lib/llt/core_extensions/object_spec.rb
124
+ - spec/lib/llt/core_extensions/symbol_spec.rb
125
+ - spec/spec_helper.rb