acronyms 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/Gemfile +12 -0
- data/Guardfile +7 -0
- data/README.md +15 -0
- data/Rakefile +46 -0
- data/lib/acronyms.rb +29 -0
- data/lib/version.rb +6 -0
- data/scripts/bump_version +47 -0
- data/scripts/check_flay +30 -0
- data/scripts/check_flog +31 -0
- data/scripts/git_hooks/pre-commit +16 -0
- data/scripts/git_hooks/pre-push +9 -0
- data/scripts/lint +2 -0
- data/scripts/release +15 -0
- data/scripts/test +4 -0
- data/scripts/watch +4 -0
- data/spec/acronyms_spec.rb +82 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/spec_helper_simplecov.rb +9 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2434f3f8985c7065e9bc5987535e448bb91f38ab
|
4
|
+
data.tar.gz: b7e052fc020ccaebc9f6e08bdecc624c8f16a587
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2941eb3cc0957df8cbe51b9198ce9109548f6f756e70fec08320d2e2914a44b84fe3b24fb9b0fe5e1cf07343d3076eb7300e9c5500199994a53ad6155befc562
|
7
|
+
data.tar.gz: 1dc0d0f48e23f9487eaedd304a1db9932864588c77cb36c034f76c380fe2594667f5300a6ec1db94a3099e2df58b424d7682cff20ea07f09e12a7b4aa6288a6a
|
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem 'coveralls', '~> 0.8'
|
5
|
+
gem 'flay', '~> 2.6'
|
6
|
+
gem 'flog', '~> 4.3'
|
7
|
+
gem 'guard-rspec', '~> 4.6'
|
8
|
+
gem 'jeweler', '~> 2.0'
|
9
|
+
gem 'rspec', '~> 3.0'
|
10
|
+
gem 'rubocop', '~> 0.31'
|
11
|
+
gem 'simplecov', '~> 0.10'
|
12
|
+
end
|
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# acronyms
|
2
|
+
|
3
|
+
Ruby gem for generating acronyms from string.
|
4
|
+
|
5
|
+
```
|
6
|
+
'Grand Theft Auto'.acronyms
|
7
|
+
=> ['GTA']
|
8
|
+
'Counter-Strike'.acronyms
|
9
|
+
=> ['CS']
|
10
|
+
'Left 4 Dead'.acronyms
|
11
|
+
=> ['L4D']
|
12
|
+
'Grand Theft Auto IV'.acronyms
|
13
|
+
['GTAIV', 'GTA4']
|
14
|
+
```
|
15
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
require_relative 'lib/version'
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see
|
18
|
+
# http://guides.rubygems.org/specification-reference/ for more options
|
19
|
+
gem.name = 'acronyms'
|
20
|
+
gem.version = AcronymsVersion.to_s
|
21
|
+
gem.homepage = 'https://github.com/pixelastic/acronyms'
|
22
|
+
gem.license = 'MIT'
|
23
|
+
gem.summary = 'Generate acronyms from strings'
|
24
|
+
gem.description = 'Generate acronyms from strings'
|
25
|
+
gem.email = 'tim@pixelastic.com'
|
26
|
+
gem.authors = ['Tim Carry']
|
27
|
+
|
28
|
+
# dependencies defined in Gemfile
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rspec/core'
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
35
|
+
spec.rspec_opts = '--color --format documentation'
|
36
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
37
|
+
end
|
38
|
+
task test: :spec
|
39
|
+
|
40
|
+
desc 'Code coverage detail'
|
41
|
+
task :coverage do
|
42
|
+
ENV['COVERAGE'] = 'true'
|
43
|
+
Rake::Task['spec'].execute
|
44
|
+
end
|
45
|
+
|
46
|
+
task default: :test
|
data/lib/acronyms.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
# Extending base String class with `.acronyms`
|
5
|
+
class String
|
6
|
+
def acronyms
|
7
|
+
return [] if empty?
|
8
|
+
split = self.split(/[\s\-]/)
|
9
|
+
|
10
|
+
romans = %w(I II III IV V VI VII VIII IX)
|
11
|
+
|
12
|
+
# If a word is a roman numeral, we keep it, othewise we take the first
|
13
|
+
# letter
|
14
|
+
acronym = split.map do |word|
|
15
|
+
romans.index(word).nil? ? word[0] : word
|
16
|
+
end
|
17
|
+
acronym = acronym.join('')
|
18
|
+
|
19
|
+
# If a word is a roman numeral, we convert it, otherwise we take the first
|
20
|
+
# letter
|
21
|
+
acronym_roman = split.map do |word|
|
22
|
+
roman_index = romans.index(word)
|
23
|
+
!roman_index.nil? ? roman_index + 1 : word.upcase[0]
|
24
|
+
end
|
25
|
+
acronym_roman = acronym_roman.join('')
|
26
|
+
|
27
|
+
[acronym, acronym_roman].uniq
|
28
|
+
end
|
29
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/version.rb'
|
3
|
+
|
4
|
+
class BumpVersion
|
5
|
+
def initialize(*args)
|
6
|
+
@type = args[0]
|
7
|
+
if !valid_type?(@type)
|
8
|
+
puts "Invalid bump type: #{@type}"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid_type?(type)
|
14
|
+
%w(major minor patch).include?(type)
|
15
|
+
end
|
16
|
+
|
17
|
+
def bump(current_version, type)
|
18
|
+
major, minor, patch = current_version.split('.').map(&:to_i)
|
19
|
+
if type == 'major'
|
20
|
+
major += 1
|
21
|
+
minor = 0
|
22
|
+
patch = 0
|
23
|
+
end
|
24
|
+
if type == 'minor'
|
25
|
+
minor += 1
|
26
|
+
patch = 0
|
27
|
+
end
|
28
|
+
patch += 1 if type == 'patch'
|
29
|
+
"#{major}.#{minor}.#{patch}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def run
|
33
|
+
old_version = AcronymsVersion.to_s
|
34
|
+
new_version = bump(old_version, @type)
|
35
|
+
|
36
|
+
script_dir = File.expand_path(File.dirname(__FILE__))
|
37
|
+
file = File.join(script_dir, '../lib/version.rb')
|
38
|
+
old_content = File.read(file)
|
39
|
+
new_content = old_content.gsub(old_version, new_version)
|
40
|
+
File.write(file, new_content)
|
41
|
+
|
42
|
+
`git add #{file}`
|
43
|
+
`git commit -m "chore(bump): Version bump to #{new_version}"`
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
BumpVersion.new(*ARGV).run
|
data/scripts/check_flay
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
MAX_SCORE = 45
|
4
|
+
|
5
|
+
flay_lines = `flay -s ./lib/`.split("\n")
|
6
|
+
|
7
|
+
errors = []
|
8
|
+
flay_lines.each_with_index do |line, index|
|
9
|
+
# Skip header
|
10
|
+
next if index < 2
|
11
|
+
|
12
|
+
pattern = /^ *(.*): (.*)/
|
13
|
+
matches = line.match(pattern)
|
14
|
+
next if matches.nil?
|
15
|
+
score = matches[1].to_f
|
16
|
+
|
17
|
+
next if score < MAX_SCORE
|
18
|
+
errors << {
|
19
|
+
score: score,
|
20
|
+
file: matches[2]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
exit 0 if errors.size == 0
|
25
|
+
|
26
|
+
puts 'Flay test failed:'
|
27
|
+
errors.sort_by { |a| a[:score] }.each do |error|
|
28
|
+
puts "#{error[:score]} / #{MAX_SCORE} in #{error[:file]}"
|
29
|
+
end
|
30
|
+
exit 1
|
data/scripts/check_flog
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
MAX_SCORE = 45
|
4
|
+
|
5
|
+
flog_lines = `flog ./lib/`.split("\n")
|
6
|
+
|
7
|
+
errors = []
|
8
|
+
flog_lines.each_with_index do |line, index|
|
9
|
+
# Skip header
|
10
|
+
next if index < 3
|
11
|
+
|
12
|
+
pattern = /^ *(.*): (.*) (.*):[0-9]*/
|
13
|
+
matches = line.match(pattern)
|
14
|
+
next if matches.nil?
|
15
|
+
score = matches[1].to_f
|
16
|
+
|
17
|
+
next if score < MAX_SCORE
|
18
|
+
errors << {
|
19
|
+
score: score,
|
20
|
+
method: matches[2],
|
21
|
+
file: matches[3]
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
exit 0 if errors.size == 0
|
26
|
+
|
27
|
+
puts 'Flog test failed:'
|
28
|
+
errors.sort_by { |a| a[:score] }.each do |error|
|
29
|
+
puts "#{error[:score]} / #{MAX_SCORE}: #{error[:method]} in #{error[:file]}"
|
30
|
+
end
|
31
|
+
exit 1
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# Succeed fast if we did not change any ruby file
|
4
|
+
if ! git status --short | grep -q '\.rb$'; then
|
5
|
+
exit 0
|
6
|
+
fi
|
7
|
+
|
8
|
+
# Do not commit any focused or excluded tests
|
9
|
+
if grep --color -r 'spec' -E -e '^( |\t)*(fit|fdescribe|xit|xdescribe)'; then
|
10
|
+
echo '✘ You have focused and/or skipped tests'
|
11
|
+
exit 1
|
12
|
+
fi
|
13
|
+
|
14
|
+
# Match style guide
|
15
|
+
./scripts/lint || exit 1
|
16
|
+
|
data/scripts/lint
ADDED
data/scripts/release
ADDED
data/scripts/test
ADDED
data/scripts/watch
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe(String) do
|
4
|
+
describe 'acronyms' do
|
5
|
+
it 'should return an array' do
|
6
|
+
# Given
|
7
|
+
input = 'Grand Theft Auto'
|
8
|
+
|
9
|
+
# When
|
10
|
+
actual = input.acronyms
|
11
|
+
|
12
|
+
# Then
|
13
|
+
expect(actual).to be_instance_of(Array)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should contain first letter of each word' do
|
17
|
+
# Given
|
18
|
+
input = 'Grand Theft Auto'
|
19
|
+
|
20
|
+
# When
|
21
|
+
actual = input.acronyms
|
22
|
+
|
23
|
+
# Then
|
24
|
+
expect(actual).to include('GTA')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return an empty array on empty string' do
|
28
|
+
# Given
|
29
|
+
input = ''
|
30
|
+
|
31
|
+
# When
|
32
|
+
actual = input.acronyms
|
33
|
+
|
34
|
+
# Then
|
35
|
+
expect(actual).to eql([])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should split on dashes' do
|
39
|
+
# Given
|
40
|
+
input = 'Counter-Strike'
|
41
|
+
|
42
|
+
# When
|
43
|
+
actual = input.acronyms
|
44
|
+
|
45
|
+
# Then
|
46
|
+
expect(actual).to include('CS')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should handle numerals' do
|
50
|
+
# Given
|
51
|
+
input = 'Left 4 Dead'
|
52
|
+
|
53
|
+
# When
|
54
|
+
actual = input.acronyms
|
55
|
+
|
56
|
+
# Then
|
57
|
+
expect(actual).to include('L4D')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should keep roman numerals' do
|
61
|
+
# Given
|
62
|
+
input = 'Grand Theft Auto IV'
|
63
|
+
|
64
|
+
# When
|
65
|
+
actual = input.acronyms
|
66
|
+
|
67
|
+
# Then
|
68
|
+
expect(actual).to include('GTAIV')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should convert roman numerals' do
|
72
|
+
# Given
|
73
|
+
input = 'Grand Theft Auto IV'
|
74
|
+
|
75
|
+
# When
|
76
|
+
actual = input.acronyms
|
77
|
+
|
78
|
+
# Then
|
79
|
+
expect(actual).to include('GTA4')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
if ENV['TRAVIS']
|
2
|
+
require 'coveralls'
|
3
|
+
Coveralls.wear!
|
4
|
+
end
|
5
|
+
|
6
|
+
require_relative './spec_helper_simplecov.rb'
|
7
|
+
require './lib/acronyms.rb'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.filter_run(focus: true)
|
11
|
+
config.fail_fast = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acronyms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Carry
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: coveralls
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: flay
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: flog
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.31'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.31'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.10'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.10'
|
125
|
+
description: Generate acronyms from strings
|
126
|
+
email: tim@pixelastic.com
|
127
|
+
executables: []
|
128
|
+
extensions: []
|
129
|
+
extra_rdoc_files:
|
130
|
+
- README.md
|
131
|
+
files:
|
132
|
+
- ".rspec"
|
133
|
+
- Gemfile
|
134
|
+
- Guardfile
|
135
|
+
- README.md
|
136
|
+
- Rakefile
|
137
|
+
- lib/acronyms.rb
|
138
|
+
- lib/version.rb
|
139
|
+
- scripts/bump_version
|
140
|
+
- scripts/check_flay
|
141
|
+
- scripts/check_flog
|
142
|
+
- scripts/git_hooks/pre-commit
|
143
|
+
- scripts/git_hooks/pre-push
|
144
|
+
- scripts/lint
|
145
|
+
- scripts/release
|
146
|
+
- scripts/test
|
147
|
+
- scripts/watch
|
148
|
+
- spec/acronyms_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
- spec/spec_helper_simplecov.rb
|
151
|
+
homepage: https://github.com/pixelastic/acronyms
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.4.8
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Generate acronyms from strings
|
175
|
+
test_files: []
|