arrayish 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
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.example ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in arrayish.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 baob
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,33 @@
1
+ # Arrayish
2
+
3
+ The gem introduces the Arrayish::String class, a string that has
4
+ some array characteristics.
5
+
6
+ Arrayish::String simplifies and DRYs code where an array appears in a
7
+ string with delimiters.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'arrayish'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install arrayish
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/arrayish.gemspec ADDED
@@ -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 'arrayish/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "arrayish"
8
+ spec.version = Arrayish::VERSION
9
+ spec.authors = ["baob"]
10
+ spec.email = ["coder@onesandthrees.com"]
11
+ spec.description = %q{ The gem introduces the Arrayish::String class, a string that has some array characteristics. }
12
+ spec.summary = %q{ Arrayish::String simplifies and DRYs code where an array appears in a string with delimiters. }
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 "pry"
25
+ end
@@ -0,0 +1,39 @@
1
+ module Arrayish
2
+ class String < ::String
3
+
4
+ def initialize(*args)
5
+ if args.respond_to? :each
6
+ super(args.join(separator))
7
+ else
8
+ super
9
+ end
10
+ end
11
+
12
+ def to_a
13
+ self.split(separator)
14
+ end
15
+
16
+ def +(something)
17
+ new_string( self.to_a + coerce_to_array(something) )
18
+ end
19
+
20
+ def [](*args)
21
+ new_string( self.to_a.send(:[],*args) )
22
+ end
23
+
24
+ private
25
+
26
+ def separator
27
+ ','
28
+ end
29
+
30
+ def coerce_to_array(input)
31
+ [input]
32
+ end
33
+
34
+ def new_string(something)
35
+ self.class.new(something)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Arrayish
2
+ VERSION = "0.0.2"
3
+ end
data/lib/arrayish.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "arrayish/version"
2
+ require "arrayish/string"
3
+
4
+ module Arrayish
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module Arrayish
4
+ describe String do
5
+ let(:a_string) { 'abcde' }
6
+ let(:x_string) { 'xyz' }
7
+
8
+ it 'is a kind of string' do
9
+ expect( subject ).to be_kind_of( ::String )
10
+ end
11
+
12
+ context 'initialised with a string' do
13
+ subject{ described_class.new(a_string) }
14
+
15
+ specify 'it equals the string' do
16
+ expect( subject ).to eql(a_string)
17
+ end
18
+
19
+ specify '#to_a returns the string in an array' do
20
+ expect( subject.to_a ).to eql( [a_string] )
21
+ end
22
+
23
+ it_behaves_like 'an arrayish string'
24
+ end
25
+
26
+ context 'initialised with an array of two strings' do
27
+ subject{ described_class.new([a_string, x_string]) }
28
+
29
+ specify 'it equals the strings joined with separator' do
30
+ expect( subject ).to eql("#{a_string},#{x_string}")
31
+ end
32
+
33
+ specify '#to_a returns the strings in an array' do
34
+ expect( subject.to_a ).to eql( [a_string,x_string] )
35
+ end
36
+
37
+ it_behaves_like 'an arrayish string'
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ shared_examples 'an arrayish string' do
2
+
3
+ it '+ with a string adds the string with a separator' do
4
+ added_string = '1234'
5
+ expect( subject + added_string ).to eql( "#{subject},#{added_string}" )
6
+ end
7
+
8
+ it '+ with an array adds the array elements with separators' do
9
+ added_array = [ '1234', '789' ]
10
+ expect( subject + added_array ).to eql( "#{subject},#{added_array[0]},#{added_array[1]}" )
11
+ end
12
+
13
+ specify '[0] operator selects from the array' do
14
+ expect( subject[0] ).to eql( described_class.new( subject.to_a[0] ) )
15
+ end
16
+
17
+ specify '[-1] operator selects from the array' do
18
+ expect( subject[-1] ).to eql( described_class.new( subject.to_a[-1] ) )
19
+ end
20
+
21
+ end
@@ -0,0 +1,31 @@
1
+ $:.unshift File.expand_path('lib')
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ require 'arrayish'
7
+
8
+ require 'rspec'
9
+ require 'pry'
10
+
11
+ %w(support shared_examples).each do |dir|
12
+ Dir[File.expand_path("spec/#{dir}/**/*.rb")].each(&method(:require))
13
+ end
14
+
15
+ # This file was generated by the `rspec --init` command. Conventionally, all
16
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
17
+ # Require this file using `require "spec_helper"` to ensure that it is only
18
+ # loaded once.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ config.treat_symbols_as_metadata_keys_with_true_values = true
23
+ config.run_all_when_everything_filtered = true
24
+ config.filter_run :focus
25
+
26
+ # Run specs in random order to surface order dependencies. If you find an
27
+ # order dependency and want to debug it, you can fix the order by providing
28
+ # the seed, which is printed after each run.
29
+ # --seed 1234
30
+ config.order = 'random'
31
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arrayish
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - baob
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
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: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! ' The gem introduces the Arrayish::String class, a string that has
79
+ some array characteristics. '
80
+ email:
81
+ - coder@onesandthrees.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - .rspec.example
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - arrayish.gemspec
93
+ - lib/arrayish.rb
94
+ - lib/arrayish/string.rb
95
+ - lib/arrayish/version.rb
96
+ - spec/lib/arrayish/string_spec.rb
97
+ - spec/shared_examples/arrayish_string.rb
98
+ - spec/spec_helper.rb
99
+ homepage: ''
100
+ licenses:
101
+ - MIT
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 1.8.25
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Arrayish::String simplifies and DRYs code where an array appears in a string
124
+ with delimiters.
125
+ test_files:
126
+ - spec/lib/arrayish/string_spec.rb
127
+ - spec/shared_examples/arrayish_string.rb
128
+ - spec/spec_helper.rb
129
+ has_rdoc: