sleeping_king_studios-tools 0.6.0 → 0.7.0.alpha.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83685650ea80f1fa0a03b22981978defb5d3386b
4
- data.tar.gz: cb05c84a361bca80fe33ca5f9a75bc30cb6694d8
3
+ metadata.gz: 5f27a979de124657efcdfa2d4b8293b2c8d71458
4
+ data.tar.gz: c7a28bce980002ba427a38e491130a29fb29672e
5
5
  SHA512:
6
- metadata.gz: 8309254a1b32fc7338f82309c5df516c2b3b3f88d7c79460c46504488c84a8abd8469bfecca3fb3407c863c2c03005d32fa082cf4a7f00c1c58a1bcc68aea019
7
- data.tar.gz: f7bc789290f287c3142a9b638ef1592fbef1235facd727c86b429a64b351bd6930563c503e09a0ba9de7b80fab76835407dc3ad19da99774f8012f7a92613e9f
6
+ metadata.gz: 6b229bf6aa673e10662fc71cbeb5b55b0f4c3eaf3d9959dcff67895595b5074e03a61238c35c36f779e545672bb5669d7f08805b46b0360f77d2824741ad5db8
7
+ data.tar.gz: 7c0546a0349e2d556976f5356abfc77bb710b6d477f2d4e23d05b422a50d8f6c32fe1a9105bd15e77a98c2895696c0f5dccca6556fe2d0657bdd301a4b0f0664
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## Upcoming Release
4
+
5
+ ### 0.7.0
6
+
7
+ #### Tools
8
+
9
+ - Support symbol arguments to StringTools methods.
10
+ - Implement StringTools#chain.
11
+ - Implement StringTools#indent.
12
+ - Implement StringTools#map_lines.
13
+
14
+ #### Misc.
15
+
16
+ - SleepingKingStudios::Tools::Toolbelt is now autoloaded from SleepingKingStudios::Tools.
17
+
3
18
  ## Current Release
4
19
 
5
20
  ### 0.6.0
data/DEVELOPMENT.md CHANGED
@@ -2,12 +2,6 @@
2
2
 
3
3
  ## 0.7.0
4
4
 
5
- - StringTools - support symbolic arguments
6
- - StringTools#chain |
7
-
8
- tools.chain(str, :underscore, :pluralize)
9
- #=> shorthand for tools.pluralize(tools.underscore str)
10
-
11
5
  - IntegerTools#pluralize - have third (plural string) parameter be optional and defer to StringTools#pluralize.
12
6
 
13
7
  - Toolbelt should be autoloaded via Tools.
@@ -21,10 +15,6 @@
21
15
  - HashTools::slice, ::bisect_keys
22
16
  - ObjectTools::apply_with_arity
23
17
  - ObjectTools::method_arity
24
- - StringTools#map_lines |
25
-
26
- tools.map_lines("10\n20 GOTO 10") { |str| " #{str}" }
27
- #=> " 10\n 20 GOTO 10"
28
18
  - Delegator#delegate, :prefix => prefix_name
29
19
 
30
20
  #### Tools
data/README.md CHANGED
@@ -16,7 +16,7 @@ Hi, I'm Rob Smith, a Ruby Engineer and the developer of this library. I use thes
16
16
 
17
17
  The tools can be accessed in a convenient form using the Toolbelt class.
18
18
 
19
- require 'sleeping_king_studios/tools/toolbelt'
19
+ require 'sleeping_king_studios/tools'
20
20
 
21
21
  tools = ::SleepingKingStudios::Tools::Toolbelt.instance
22
22
 
@@ -532,6 +532,50 @@ Converts a lowercase, underscore separated string to a mixed-case string express
532
532
  StringTools#camelize 'muspelheimr_and_niflheimr'
533
533
  #=> 'MuspelheimrAndNiflheimr'
534
534
 
535
+ #### `#chain`
536
+
537
+ Performs multiple string tools operations in sequence, starting with the given string and passing the result of each operation to the next.
538
+
539
+ # Equivalent to `StringTools.underscore(StringTools.pluralize str)`.
540
+ StringTools#chain 'ArchivedPeriodical', :underscore, :pluralize
541
+ # => 'archived_periodicals'
542
+
543
+ Adds the specified number of spaces to the start of each line of the string. Defaults to 2 spaces.
544
+
545
+ string = 'The Hobbit'
546
+ StringTools.indent(string)
547
+ #=> ' The Hobbit'
548
+
549
+ titles = [
550
+ "The Fellowship of the Ring",
551
+ "The Two Towers",
552
+ "The Return of the King"
553
+ ] # end titles
554
+ string = titles.join "\n"
555
+ StringTools.indent(string, 4)
556
+ #=> " The Fellowship of the Ring\n"\
557
+ " The Two Towers\n"\
558
+ " The Return of the King"
559
+
560
+ #### `#map_lines`
561
+
562
+ Yields each line of the string to the provided block and combines the results into a new multiline string.
563
+
564
+ string = 'The Hobbit'
565
+ StringTools.map_lines(string) { |line| " #{line}" }
566
+ #=> '- The Hobbit'
567
+
568
+ titles = [
569
+ "The Fellowship of the Ring",
570
+ "The Two Towers",
571
+ "The Return of the King"
572
+ ] # end titles
573
+ string = titles.join "\n"
574
+ StringTools.map_lines(string) { |line, index| "#{index}. #{line}" }
575
+ #=> "0. The Fellowship of the Ring\n"\
576
+ "1. The Two Towers\n"\
577
+ "2. The Return of the King"
578
+
535
579
  #### `#plural?`
536
580
 
537
581
  Returns true if the word is in plural form, and returns false otherwise. A word is in plural form if and only if calling `#pluralize` (see below) on the word returns the word without modification.
@@ -18,13 +18,26 @@ module SleepingKingStudios::Tools
18
18
  #
19
19
  # @see ActiveSupport::Inflector#camelize.
20
20
  def camelize str
21
- require_string! str
21
+ str = require_string! str
22
22
 
23
23
  str = str.dup
24
24
  str.gsub!(/(\b|[_-])([a-z])/) { |match| $2.upcase }
25
25
  str
26
26
  end # method camelize
27
27
 
28
+ # Performs multiple string tools operations in sequence, starting with the
29
+ # given string and passing the result of each operation to the next.
30
+ #
31
+ # @param str [String] The string to process.
32
+ # @param commands [Array<String, Symbol>] The string operations to apply.
33
+ #
34
+ # @return [String] The processed string.
35
+ def chain str, *commands
36
+ str = require_string! str
37
+
38
+ commands.reduce(str) { |memo, command| send(command, memo) }
39
+ end # method chain
40
+
28
41
  # (see PluralInflector#define_irregular_word)
29
42
  def define_irregular_word singular, plural
30
43
  plural_inflector.define_irregular_word singular, plural
@@ -45,11 +58,44 @@ module SleepingKingStudios::Tools
45
58
  plural_inflector.define_uncountable_word word
46
59
  end # method define_uncountable_word
47
60
 
61
+ # Adds the specified number of spaces to the start of each line of the
62
+ # string. Defaults to 2 spaces.
63
+ #
64
+ # @param str [String] The string to indent.
65
+ # @param count [Integer] The number of spaces to add.
66
+ #
67
+ # @return [String] The indented string.
68
+ def indent str, count = 2
69
+ str = require_string! str
70
+ pre = " " * count
71
+
72
+ map_lines(str) { |line| "#{pre}#{line}" }
73
+ end # method indent
74
+
75
+ # Yields each line of the string to the provided block and combines the
76
+ # results into a new multiline string.
77
+ #
78
+ # @param str [String] The string to map.
79
+ #
80
+ # @yieldparam line [String] The current line.
81
+ # @yieldparam index [Integer] The index of the current line.
82
+ #
83
+ # @return [String] The mapped string.
84
+ def map_lines str
85
+ str = require_string! str
86
+
87
+ str.each_line.with_index.reduce('') do |memo, (line, index)|
88
+ memo << yield(line, index)
89
+ end # each_line
90
+ end # method map_lines
91
+
48
92
  # Determines whether or not the given word is in plural form. If calling
49
93
  # #pluralize(word) is equal to word, the word is considered plural.
50
94
  #
51
95
  # @return [Boolean] True if the word is in plural form, otherwise false.
52
96
  def plural? word
97
+ word = require_string!(word)
98
+
53
99
  word == pluralize(word)
54
100
  end # method plural?
55
101
 
@@ -87,9 +133,9 @@ module SleepingKingStudios::Tools
87
133
  return IntegerTools.pluralize(*args)
88
134
  end # if
89
135
 
90
- require_string! args.first
136
+ str = require_string! args.first
91
137
 
92
- plural_inflector.pluralize args.first
138
+ plural_inflector.pluralize str
93
139
  end # method pluralize
94
140
 
95
141
  # Determines whether or not the given word is in singular form. If calling
@@ -97,6 +143,8 @@ module SleepingKingStudios::Tools
97
143
  #
98
144
  # @return [Boolean] True if the word is in singular form, otherwise false.
99
145
  def singular? word
146
+ word = require_string!(word)
147
+
100
148
  word == singularize(word)
101
149
  end # method singular?
102
150
 
@@ -125,7 +173,7 @@ module SleepingKingStudios::Tools
125
173
  #
126
174
  # @see ActiveSupport::Inflector#underscore.
127
175
  def underscore str
128
- require_string! str
176
+ str = require_string! str
129
177
 
130
178
  str = str.dup
131
179
  str.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
@@ -142,7 +190,9 @@ module SleepingKingStudios::Tools
142
190
  end # method plural_inflector
143
191
 
144
192
  def require_string! value
145
- return if string?(value)
193
+ return value if string?(value)
194
+
195
+ return value.to_s if value.is_a?(Symbol)
146
196
 
147
197
  raise ArgumentError, 'argument must be a string', caller[1..-1]
148
198
  end # method require_array
@@ -13,10 +13,10 @@ module SleepingKingStudios
13
13
  private
14
14
 
15
15
  MAJOR = 0
16
- MINOR = 6
16
+ MINOR = 7
17
17
  PATCH = 0
18
- PRERELEASE = nil
19
- BUILD = nil
18
+ PRERELEASE = :alpha
19
+ BUILD = 0
20
20
  end # module
21
21
 
22
22
  VERSION = Version.to_gem_version
@@ -4,7 +4,9 @@
4
4
  module SleepingKingStudios
5
5
  # A library of utility services and concerns to expand the functionality of
6
6
  # core classes without polluting the global namespace.
7
- module Tools; end
7
+ module Tools
8
+ autoload :Toolbelt, 'sleeping_king_studios/tools/toolbelt'
9
+ end # module
8
10
  end # module
9
11
 
10
12
  require 'sleeping_king_studios/tools/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sleeping_king_studios-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0.alpha.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob "Merlin" Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-27 00:00:00.000000000 Z
11
+ date: 2017-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -124,12 +124,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - ">="
127
+ - - ">"
128
128
  - !ruby/object:Gem::Version
129
- version: '0'
129
+ version: 1.3.1
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.5.1
132
+ rubygems_version: 2.6.11
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: A library of utility services and concerns.