semantic_linefeeds 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/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +233 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +131 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/semantic-linefeeds +5 -0
- data/lib/semantic_linefeeds.rb +5 -0
- data/lib/semantic_linefeeds/cli.rb +25 -0
- data/lib/semantic_linefeeds/converter.rb +34 -0
- data/lib/semantic_linefeeds/version.rb +3 -0
- data/notes.md +22 -0
- data/semantic_linefeeds.gemspec +26 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: edc9aa0ab2ce73fe2a8fd2b431df3bd0b17a541b
|
4
|
+
data.tar.gz: bf4d399a6d34d318a5dcf2e4cfcb2851c39de48c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2182223bacca0317033c3731532a059d2f947296035e820521d81584d7fdc6187dff3bc35a74659ed29cc9f899bde4db48a0a593a53a58a8eda27c179e832f9c
|
7
|
+
data.tar.gz: 1be05cd06119022376aef2d45380ebbbff98111f9848e6407bd2b6fe782c598cbe19885fb3090f631538c68f8111f817ded8e290013830641c5d1b02f38a719c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "vendor/**/*"
|
4
|
+
- "db/schema.rb"
|
5
|
+
UseCache: false
|
6
|
+
Style/CollectionMethods:
|
7
|
+
Description: Preferred collection methods.
|
8
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
|
9
|
+
Enabled: true
|
10
|
+
PreferredMethods:
|
11
|
+
collect: map
|
12
|
+
collect!: map!
|
13
|
+
find: detect
|
14
|
+
find_all: select
|
15
|
+
reduce: inject
|
16
|
+
Style/DotPosition:
|
17
|
+
Description: Checks the position of the dot in multi-line method calls.
|
18
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
|
19
|
+
Enabled: true
|
20
|
+
EnforcedStyle: trailing
|
21
|
+
SupportedStyles:
|
22
|
+
- leading
|
23
|
+
- trailing
|
24
|
+
Style/FileName:
|
25
|
+
Description: Use snake_case for source file names.
|
26
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
|
27
|
+
Enabled: false
|
28
|
+
Exclude: []
|
29
|
+
Style/GuardClause:
|
30
|
+
Description: Check for conditionals that can be replaced with guard clauses
|
31
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
|
32
|
+
Enabled: false
|
33
|
+
MinBodyLength: 1
|
34
|
+
Style/IfUnlessModifier:
|
35
|
+
Description: Favor modifier if/unless usage when you have a single-line body.
|
36
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
|
37
|
+
Enabled: false
|
38
|
+
MaxLineLength: 80
|
39
|
+
Style/OptionHash:
|
40
|
+
Description: Don't use option hashes when you can use keyword arguments.
|
41
|
+
Enabled: false
|
42
|
+
Style/PercentLiteralDelimiters:
|
43
|
+
Description: Use `%`-literal delimiters consistently
|
44
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
|
45
|
+
Enabled: false
|
46
|
+
PreferredDelimiters:
|
47
|
+
"%": "()"
|
48
|
+
"%i": "()"
|
49
|
+
"%q": "()"
|
50
|
+
"%Q": "()"
|
51
|
+
"%r": "{}"
|
52
|
+
"%s": "()"
|
53
|
+
"%w": "()"
|
54
|
+
"%W": "()"
|
55
|
+
"%x": "()"
|
56
|
+
Style/PredicateName:
|
57
|
+
Description: Check the names of predicate methods.
|
58
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
|
59
|
+
Enabled: true
|
60
|
+
NamePrefix:
|
61
|
+
- is_
|
62
|
+
- has_
|
63
|
+
- have_
|
64
|
+
NamePrefixBlacklist:
|
65
|
+
- is_
|
66
|
+
Exclude:
|
67
|
+
- spec/**/*
|
68
|
+
Style/RaiseArgs:
|
69
|
+
Description: Checks the arguments passed to raise/fail.
|
70
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
|
71
|
+
Enabled: false
|
72
|
+
EnforcedStyle: exploded
|
73
|
+
SupportedStyles:
|
74
|
+
- compact
|
75
|
+
- exploded
|
76
|
+
Style/SignalException:
|
77
|
+
Description: Checks for proper usage of fail and raise.
|
78
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
|
79
|
+
Enabled: false
|
80
|
+
EnforcedStyle: semantic
|
81
|
+
SupportedStyles:
|
82
|
+
- only_raise
|
83
|
+
- only_fail
|
84
|
+
- semantic
|
85
|
+
Style/SingleLineBlockParams:
|
86
|
+
Description: Enforces the names of some block params.
|
87
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
|
88
|
+
Enabled: false
|
89
|
+
Methods:
|
90
|
+
- reduce:
|
91
|
+
- a
|
92
|
+
- e
|
93
|
+
- inject:
|
94
|
+
- a
|
95
|
+
- e
|
96
|
+
Style/SingleLineMethods:
|
97
|
+
Description: Avoid single-line methods.
|
98
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
|
99
|
+
Enabled: false
|
100
|
+
AllowIfMethodIsEmpty: true
|
101
|
+
Style/StringLiterals:
|
102
|
+
Description: Checks if uses of quotes match the configured preference.
|
103
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
|
104
|
+
Enabled: true
|
105
|
+
EnforcedStyle: double_quotes
|
106
|
+
SupportedStyles:
|
107
|
+
- single_quotes
|
108
|
+
- double_quotes
|
109
|
+
Style/StringLiteralsInInterpolation:
|
110
|
+
Description: Checks if uses of quotes inside expressions in interpolated strings
|
111
|
+
match the configured preference.
|
112
|
+
Enabled: true
|
113
|
+
EnforcedStyle: single_quotes
|
114
|
+
SupportedStyles:
|
115
|
+
- single_quotes
|
116
|
+
- double_quotes
|
117
|
+
Style/TrailingComma:
|
118
|
+
Description: Checks for trailing comma in parameter lists and literals.
|
119
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
|
120
|
+
Enabled: false
|
121
|
+
EnforcedStyleForMultiline: no_comma
|
122
|
+
SupportedStyles:
|
123
|
+
- comma
|
124
|
+
- no_comma
|
125
|
+
Metrics/AbcSize:
|
126
|
+
Description: A calculated magnitude based on number of assignments, branches, and
|
127
|
+
conditions.
|
128
|
+
Enabled: false
|
129
|
+
Max: 15
|
130
|
+
Metrics/ClassLength:
|
131
|
+
Description: Avoid classes longer than 100 lines of code.
|
132
|
+
Enabled: false
|
133
|
+
CountComments: false
|
134
|
+
Max: 100
|
135
|
+
Metrics/ModuleLength:
|
136
|
+
CountComments: false
|
137
|
+
Max: 100
|
138
|
+
Description: Avoid modules longer than 100 lines of code.
|
139
|
+
Enabled: false
|
140
|
+
Metrics/CyclomaticComplexity:
|
141
|
+
Description: A complexity metric that is strongly correlated to the number of test
|
142
|
+
cases needed to validate a method.
|
143
|
+
Enabled: false
|
144
|
+
Max: 6
|
145
|
+
Metrics/MethodLength:
|
146
|
+
Description: Avoid methods longer than 10 lines of code.
|
147
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
|
148
|
+
Enabled: false
|
149
|
+
CountComments: false
|
150
|
+
Max: 10
|
151
|
+
Metrics/ParameterLists:
|
152
|
+
Description: Avoid parameter lists longer than three or four parameters.
|
153
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
|
154
|
+
Enabled: false
|
155
|
+
Max: 5
|
156
|
+
CountKeywordArgs: true
|
157
|
+
Metrics/PerceivedComplexity:
|
158
|
+
Description: A complexity metric geared towards measuring complexity for a human
|
159
|
+
reader.
|
160
|
+
Enabled: false
|
161
|
+
Max: 7
|
162
|
+
Lint/AssignmentInCondition:
|
163
|
+
Description: Don't use assignment in conditions.
|
164
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
|
165
|
+
Enabled: false
|
166
|
+
AllowSafeAssignment: true
|
167
|
+
Style/InlineComment:
|
168
|
+
Description: Avoid inline comments.
|
169
|
+
Enabled: false
|
170
|
+
Style/AccessorMethodName:
|
171
|
+
Description: Check the naming of accessor methods for get_/set_.
|
172
|
+
Enabled: false
|
173
|
+
Style/Alias:
|
174
|
+
Description: Use alias_method instead of alias.
|
175
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
|
176
|
+
Enabled: false
|
177
|
+
Style/Documentation:
|
178
|
+
Description: Document classes and non-namespace modules.
|
179
|
+
Enabled: false
|
180
|
+
Style/DoubleNegation:
|
181
|
+
Description: Checks for uses of double negation (!!).
|
182
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
183
|
+
Enabled: false
|
184
|
+
Style/EachWithObject:
|
185
|
+
Description: Prefer `each_with_object` over `inject` or `reduce`.
|
186
|
+
Enabled: false
|
187
|
+
Style/EmptyLiteral:
|
188
|
+
Description: Prefer literals to Array.new/Hash.new/String.new.
|
189
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
|
190
|
+
Enabled: false
|
191
|
+
Style/ModuleFunction:
|
192
|
+
Description: Checks for usage of `extend self` in modules.
|
193
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
|
194
|
+
Enabled: false
|
195
|
+
Style/OneLineConditional:
|
196
|
+
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
|
197
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
|
198
|
+
Enabled: false
|
199
|
+
Style/PerlBackrefs:
|
200
|
+
Description: Avoid Perl-style regex back references.
|
201
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
|
202
|
+
Enabled: false
|
203
|
+
Style/Send:
|
204
|
+
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
|
205
|
+
may overlap with existing methods.
|
206
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
|
207
|
+
Enabled: false
|
208
|
+
Style/SpecialGlobalVars:
|
209
|
+
Description: Avoid Perl-style global variables.
|
210
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
|
211
|
+
Enabled: false
|
212
|
+
Style/VariableInterpolation:
|
213
|
+
Description: Don't interpolate global, instance and class variables directly in
|
214
|
+
strings.
|
215
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
|
216
|
+
Enabled: false
|
217
|
+
Style/WhenThen:
|
218
|
+
Description: Use when x then ... for one-line cases.
|
219
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
|
220
|
+
Enabled: false
|
221
|
+
Lint/EachWithObjectArgument:
|
222
|
+
Description: Check for immutable argument given to each_with_object.
|
223
|
+
Enabled: true
|
224
|
+
Lint/HandleExceptions:
|
225
|
+
Description: Don't suppress exception.
|
226
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
|
227
|
+
Enabled: false
|
228
|
+
Lint/LiteralInCondition:
|
229
|
+
Description: Checks of literals used in conditions.
|
230
|
+
Enabled: false
|
231
|
+
Lint/LiteralInInterpolation:
|
232
|
+
Description: Checks for literals used in interpolation.
|
233
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Sean Collins
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# Semantic Linefeeds
|
2
|
+
|
3
|
+
This is a simple tool to convert text into
|
4
|
+
[semantic linefeeds](http://rhodesmill.org/brandon/2012/one-sentence-per-line/).
|
5
|
+
|
6
|
+
Rather than having a paragraph formatted as such:
|
7
|
+
```
|
8
|
+
First, when you do the purely mechanical operations of typing, type so
|
9
|
+
subsequent editing will be easy. Start each sentence on a new line. Make lines
|
10
|
+
short, and break lines at natural places, such as after commas and semicolons,
|
11
|
+
rather than randomly. Since most people change documents by rewriting phrases
|
12
|
+
and adding, deleting and rearranging sentences, these precautions simplify any
|
13
|
+
editing you have to do later.
|
14
|
+
```
|
15
|
+
|
16
|
+
You can write your text like:
|
17
|
+
```
|
18
|
+
First,
|
19
|
+
when you do the purely mechanical operations of typing,
|
20
|
+
type so subsequent editing will be easy.
|
21
|
+
Start each sentence on a new line.
|
22
|
+
Make lines short,
|
23
|
+
and break lines at natural places,
|
24
|
+
such as after commas and semicolons,
|
25
|
+
rather than randomly.
|
26
|
+
Since most people change documents by rewriting phrases and adding,
|
27
|
+
deleting and rearranging sentences,
|
28
|
+
these precautions simplify any editing you have to do later.
|
29
|
+
```
|
30
|
+
|
31
|
+
This makes `diff`ing it show more information.
|
32
|
+
If you're using a text-preprocessor like Markdown,
|
33
|
+
this is terrific,
|
34
|
+
since your source can be formatted independently
|
35
|
+
of how you display it.
|
36
|
+
|
37
|
+
Take a look at the Source of this `README.md` file
|
38
|
+
for an example :)
|
39
|
+
|
40
|
+
## Installation
|
41
|
+
|
42
|
+
Add this line to your application's Gemfile:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
gem 'semantic_linefeeds'
|
46
|
+
```
|
47
|
+
|
48
|
+
And then execute:
|
49
|
+
|
50
|
+
$ bundle
|
51
|
+
|
52
|
+
Or install it yourself as:
|
53
|
+
|
54
|
+
$ gem install semantic_linefeeds
|
55
|
+
|
56
|
+
## Usage
|
57
|
+
|
58
|
+
|
59
|
+
Once it's installed,
|
60
|
+
you can run `semantic-linefeeds`.
|
61
|
+
**NOTE**: this executable uses a hyphen to separate the words,
|
62
|
+
whereas the git repo and gem use an underscore.
|
63
|
+
|
64
|
+
The executable accepts either a string,
|
65
|
+
or a Filename.
|
66
|
+
|
67
|
+
### String example
|
68
|
+
`semantic-linefeeds Hello, I like this gem. Do you?`
|
69
|
+
|
70
|
+
will output:
|
71
|
+
|
72
|
+
```
|
73
|
+
Hello,
|
74
|
+
I like this gem.
|
75
|
+
do you?
|
76
|
+
```
|
77
|
+
|
78
|
+
### File name example
|
79
|
+
`echo "Hello, I like this gem. Do you?" > tmp.txt`
|
80
|
+
`semantic-linefeeds tmp.txt`
|
81
|
+
|
82
|
+
will output:
|
83
|
+
```
|
84
|
+
Hello,
|
85
|
+
I like this gem.
|
86
|
+
do you?
|
87
|
+
```
|
88
|
+
|
89
|
+
Note that output currently only goes to STDOUT.
|
90
|
+
|
91
|
+
If you try to do something like
|
92
|
+
```
|
93
|
+
semantic-linefeeds README.md > README.md
|
94
|
+
```
|
95
|
+
You'll end up with a blank file,
|
96
|
+
because the `>` clears the `README.md` file
|
97
|
+
before it can be read into memory.
|
98
|
+
|
99
|
+
We assume you're using git,
|
100
|
+
so the code doesn't store of a backup of the original file,
|
101
|
+
in case of errors.
|
102
|
+
|
103
|
+
## TODO:
|
104
|
+
|
105
|
+
[ ] - Add words to break on ('or, 'and', 'then')
|
106
|
+
[ ] - Allow user defined words to break on, probably via a YAML config file
|
107
|
+
[ ] - Allow writing results to a file, rather than only to STDOUT.
|
108
|
+
|
109
|
+
## Development
|
110
|
+
|
111
|
+
After checking out the repo,
|
112
|
+
run `bin/setup` to install dependencies.
|
113
|
+
Then,
|
114
|
+
run `rake spec` to run the tests.
|
115
|
+
You can also run `bin/console` for an interactive prompt
|
116
|
+
that will allow you to experiment.
|
117
|
+
|
118
|
+
## Contributing
|
119
|
+
|
120
|
+
Bug reports and pull requests are welcome on GitHub at
|
121
|
+
https://github.com/cllns/semantic_linefeeds.
|
122
|
+
This project is intended to be a safe,
|
123
|
+
welcoming space for collaboration,
|
124
|
+
and contributors are expected to adhere to the
|
125
|
+
[Contributor Covenant](contributor-covenant.org)
|
126
|
+
code of conduct.
|
127
|
+
|
128
|
+
## License
|
129
|
+
|
130
|
+
The gem is available as open source under the terms of the
|
131
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "semantic_linefeeds"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module SemanticLinefeeds
|
2
|
+
class CLI
|
3
|
+
def initialize(args)
|
4
|
+
if File.exist?(args[0])
|
5
|
+
input = File.read(args[0])
|
6
|
+
else
|
7
|
+
input = string_from_args(args)
|
8
|
+
end
|
9
|
+
|
10
|
+
puts Converter.run(input)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# If the user passes the string in surrounded by quotes, return that string.
|
16
|
+
# Else, if they don't, we'll join all the args into a string.
|
17
|
+
def string_from_args(args)
|
18
|
+
if args.is_a?(Array)
|
19
|
+
args.join(" ")
|
20
|
+
else
|
21
|
+
args
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SemanticLinefeeds
|
2
|
+
class Converter
|
3
|
+
SPLIT_AFTER = %w[
|
4
|
+
,
|
5
|
+
.
|
6
|
+
...
|
7
|
+
…
|
8
|
+
?
|
9
|
+
:
|
10
|
+
;
|
11
|
+
!
|
12
|
+
)
|
13
|
+
\]
|
14
|
+
]
|
15
|
+
|
16
|
+
SPLIT_BEFORE = %w[
|
17
|
+
(
|
18
|
+
\[
|
19
|
+
http
|
20
|
+
]
|
21
|
+
|
22
|
+
def self.run(text)
|
23
|
+
SPLIT_BEFORE.each do |splitter|
|
24
|
+
text = text.split(" #{splitter}").join("\n#{splitter}")
|
25
|
+
end
|
26
|
+
|
27
|
+
SPLIT_AFTER.each do |splitter|
|
28
|
+
text = text.split("#{splitter} ").join("#{splitter}\n")
|
29
|
+
end
|
30
|
+
|
31
|
+
text
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/notes.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Semantic Linefeed
|
2
|
+
This will convert a single text-file to semantic line feeds.
|
3
|
+
|
4
|
+
Since semantic line feeds are **semantic** we can only approximate this.
|
5
|
+
|
6
|
+
We can start by breaking on:
|
7
|
+
|
8
|
+
- .
|
9
|
+
- ,
|
10
|
+
- :
|
11
|
+
- ;
|
12
|
+
- (
|
13
|
+
- [
|
14
|
+
- —
|
15
|
+
- –
|
16
|
+
|
17
|
+
Then we can try to guess based on some words:
|
18
|
+
- that
|
19
|
+
- then
|
20
|
+
- which (should already be included with , but still)
|
21
|
+
- but ( ^^ same ^^ )
|
22
|
+
- and
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "semantic_linefeeds/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "semantic_linefeeds"
|
8
|
+
spec.version = SemanticLinefeeds::VERSION
|
9
|
+
spec.authors = ["Sean Collins"]
|
10
|
+
spec.email = ["sean@cllns.com"]
|
11
|
+
|
12
|
+
spec.summary = "Convert text to semantic linefeeds"
|
13
|
+
spec.homepage = "https://github.com/cllns/semantic_linefeeds"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: semantic_linefeeds
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Collins
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-26 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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
|
+
description:
|
56
|
+
email:
|
57
|
+
- sean@cllns.com
|
58
|
+
executables:
|
59
|
+
- semantic-linefeeds
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".rubocop.yml"
|
66
|
+
- ".travis.yml"
|
67
|
+
- CODE_OF_CONDUCT.md
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- exe/semantic-linefeeds
|
75
|
+
- lib/semantic_linefeeds.rb
|
76
|
+
- lib/semantic_linefeeds/cli.rb
|
77
|
+
- lib/semantic_linefeeds/converter.rb
|
78
|
+
- lib/semantic_linefeeds/version.rb
|
79
|
+
- notes.md
|
80
|
+
- semantic_linefeeds.gemspec
|
81
|
+
homepage: https://github.com/cllns/semantic_linefeeds
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.2.3
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Convert text to semantic linefeeds
|
105
|
+
test_files: []
|
106
|
+
has_rdoc:
|