patter 1.0.5 → 1.0.6

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
  SHA256:
3
- metadata.gz: 1b6f88f9d2e4c9a39125c9e8c1084b8eb43f51a38dc1c69a685ae78fb847121c
4
- data.tar.gz: b832125b05f90f0d26177a692ea711ee0c5565055791d98766e3eac8fa064896
3
+ metadata.gz: 5c1584eb8bd0834327c709b84b6b1e4494e2344a34cd37f23a0b9015b86ef86b
4
+ data.tar.gz: 76501c3b62bc86fe4a4bceca35f66a64b2eb6825d32d40a341b12ef2656b2187
5
5
  SHA512:
6
- metadata.gz: 502891e4d81f0d48a17632847c53fc75b476ba5badb09e49ac7bf8d9e4f494923ed054e216fdbd4cb9066d380e4a341cf25661d68c4b92488c74a4ab327dc9d3
7
- data.tar.gz: 16fe9cef721d8689f4b8f93f0be0d139afa5ef32f835dcd4d0ceab9e9b10b21e2426dfe8dfe652a14bf493798328eeb506cb4abc8901ca16712f201fb773ea6d
6
+ metadata.gz: 6608809934a669797993d55796caf297f80fcbcfcf233a224404eb5db7960da315bf3d63e6a377cefb79684977ebb9b5889066ce4ea04e029317f45334a2ac0a
7
+ data.tar.gz: 1f9653182a4ce835485990857639fa1455c0bc2172783eddd603fee0e3919e7a5b780d22d5bae6f389da686505727aedf1d9ca9f1f4be9614fdb52d6a1f750b1
data/bin/patter CHANGED
@@ -1,28 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'patter'
4
- include Patter
5
-
6
4
  require 'docopt'
7
5
 
8
6
  str = <<~EOF
9
- Usage: #{File.basename $0} [options] <pattern>
7
+ Usage: #{File.basename $0} [options] <pattern>
10
8
 
11
- Generate strings from <pattern>.
9
+ Generate strings from <pattern>.
12
10
 
13
- -n, --count N Number of patterns to generate [default: 10].
14
- -h, --help Show this help.
11
+ -n, --count N Number of patterns to generate [default: 10].
12
+ -h, --help Show this help.
13
+ -v, --version Show version.
15
14
 
16
- #{Pattern.help}
15
+ #{Patter::Pattern.help}
17
16
  EOF
18
17
 
19
18
  begin
20
- opts = Docopt::docopt(str)
19
+ opts = Docopt::docopt(str, { version: Patter::VERSION })
21
20
  rescue Docopt::Exit => e
22
- puts e.message
23
- exit
21
+ puts e.message
22
+ exit
24
23
  end
25
24
 
26
25
  opts['--count'].to_i.times do
27
- puts Pattern.new(opts['<pattern>']).to_s
26
+ puts Patter::Pattern.new(opts['<pattern>']).to_s
28
27
  end
@@ -1,73 +1,73 @@
1
1
  module Patter
2
- TAGS = {
3
- 'S' => :symbols,
4
- 'A' => :adjectives,
5
- 'D' => :digits,
6
- 'C' => :chars,
7
- 'N' => :nouns,
8
- }
2
+ TAGS = {
3
+ 'S' => :symbols,
4
+ 'A' => :adjectives,
5
+ 'D' => :digits,
6
+ 'C' => :chars,
7
+ 'N' => :nouns,
8
+ }
9
9
 
10
- MODIFIERS = {
11
- 's' => :pluralize,
12
- 'a' => :altcase,
13
- 'l' => :downcase,
14
- 'u' => :upcase,
15
- 't' => :titleize,
16
- }
10
+ MODIFIERS = {
11
+ 's' => :pluralize,
12
+ 'a' => :altcase,
13
+ 'l' => :downcase,
14
+ 'u' => :upcase,
15
+ 't' => :titleize,
16
+ }
17
17
 
18
- class Pattern
19
- def initialize pattern
20
- @pattern = pattern
21
- end
18
+ class Pattern
19
+ def initialize(pattern)
20
+ @pattern = pattern
21
+ end
22
22
 
23
- def to_s
24
- @pattern.gsub(/\{([#{TAGS.keys.join}])(:(\w+))?\}/) do
25
- tag, modifiers = $1, $3
26
- source = SourceProvider.instance.get_source(TAGS[tag])
23
+ def to_s
24
+ @pattern.gsub(/\{([#{TAGS.keys.join}])(:(\w+))?\}/) do
25
+ tag, modifiers = $1, $3
26
+ source = SourceProvider.instance.get_source(TAGS[tag])
27
27
 
28
- next source.get_sample if !modifiers
28
+ next source.get_sample if !modifiers
29
29
 
30
- re = /([#{MODIFIERS.keys.join}])|([0-9]+)/
31
- chain = []
32
- n = 1
30
+ re = /([#{MODIFIERS.keys.join}])|([0-9]+)/
31
+ chain = []
32
+ n = 1
33
33
 
34
- modifiers.split(re).reject(&:empty?).each do |modifier|
35
- n = $1.to_i if modifier =~ /([0-9]+)/
36
- chain << MODIFIERS[modifier] if MODIFIERS[modifier]
37
- end
34
+ modifiers.split(re).reject(&:empty?).each do |modifier|
35
+ n = $1.to_i if modifier =~ /([0-9]+)/
36
+ chain << MODIFIERS[modifier] if MODIFIERS[modifier]
37
+ end
38
38
 
39
- samples = source.get_samples(n)
40
- chain.each { |tran| samples.each &tran }
41
- samples.join
42
- end
43
- end
39
+ samples = source.get_samples(n)
40
+ chain.each { |tran| samples.each &tran }
41
+ samples.join
42
+ end
43
+ end
44
44
 
45
- def self.help
46
- return <<~EOF
47
- TAGS
45
+ def self.help
46
+ return <<~EOF
47
+ TAGS
48
48
 
49
- {A} adjective {N} noun
50
- {S} symbol {D} digit
51
- {C} character
49
+ {A} adjective {N} noun
50
+ {S} symbol {D} digit
51
+ {C} character
52
52
 
53
- MODIFIERS
53
+ MODIFIERS
54
54
 
55
- s: plural t: titlecase
56
- u: uppercase l: lowercase
57
- a: AlTeRnAtE case
58
- <number>: repeat <number> times
55
+ s: plural t: titlecase
56
+ u: uppercase l: lowercase
57
+ a: AlTeRnAtE case
58
+ <number>: repeat <number> times
59
59
 
60
- Apply modifiers using a colon after the tag name.
60
+ Apply modifiers using a colon after the tag name.
61
61
 
62
- EXAMPLES
62
+ EXAMPLES
63
63
 
64
- Ten random uppercase letters: {C:10u}
65
- Three camelcase nouns: {N:3t}
66
- Plural, titlecase noun: {N:ts}
67
- Uppercase adjective: {A:u}
68
- Five random digits: {D:5}
69
- A username: {A}_{N}
70
- EOF
64
+ Ten random uppercase letters: {C:10u}
65
+ Three camelcase nouns: {N:3t}
66
+ Plural, titlecase noun: {N:ts}
67
+ Uppercase adjective: {A:u}
68
+ Five random digits: {D:5}
69
+ A username: {A}_{N}
70
+ EOF
71
+ end
71
72
  end
72
- end
73
73
  end
data/lib/patter/sample.rb CHANGED
@@ -1,22 +1,26 @@
1
1
  module Patter
2
- class Sample
3
- def initialize str
4
- @str = str
5
- end
2
+ class Sample
3
+ def initialize(str)
4
+ @str = str
5
+ end
6
6
 
7
- def method_missing s
8
- @str = @str.send s
9
- end
7
+ def method_missing(method_symbol)
8
+ @str = @str.send(method_symbol)
9
+ end
10
10
 
11
- def altcase
12
- @str = @str.chars.each_with_index.map do |c, i|
13
- if i % 2 == 0 then c.upcase else c.downcase end
14
- end.join
15
- end
11
+ def altcase
12
+ @str = @str.chars.each_with_index.map do |char, i|
13
+ if i % 2 == 0 then
14
+ char.upcase
15
+ else
16
+ char.downcase
17
+ end
18
+ end.join
19
+ end
16
20
 
17
- def to_s
18
- @str
21
+ def to_s
22
+ @str
23
+ end
24
+ alias_method :to_str, :to_s
19
25
  end
20
- alias_method :to_str, :to_s
21
- end
22
26
  end
data/lib/patter/source.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  module Patter
2
- class Source < Array
3
- def get_samples n
4
- self.sample(n).map { |str| Sample.new(str) }
5
- end
2
+ class Source < Array
3
+ def get_samples(n)
4
+ sample(n).map { |str| Sample.new(str) }
5
+ end
6
6
 
7
- def get_sample
8
- get_samples(1).first
7
+ def get_sample
8
+ get_samples(1).first
9
+ end
9
10
  end
10
- end
11
11
  end
@@ -1,39 +1,39 @@
1
1
  module Patter
2
- class SourceProvider
3
- include Singleton
2
+ class SourceProvider
3
+ include Singleton
4
4
 
5
- def get_source type
6
- Source.new(send(type))
7
- end
5
+ def get_source(type)
6
+ Source.new(send(type))
7
+ end
8
8
 
9
- private
9
+ private
10
10
 
11
- def gem_root
12
- __dir__ + "/../../"
13
- end
11
+ def gem_root
12
+ __dir__ + "/../../"
13
+ end
14
14
 
15
- def get_wordlist type
16
- File.read(gem_root + "/words/#{type}.txt").split
17
- end
15
+ def get_wordlist(type)
16
+ File.read(gem_root + "/words/#{type}.txt").split
17
+ end
18
18
 
19
- def chars
20
- 'abcdefghijklmnopqrstuvwxyz'.split('').shuffle
21
- end
19
+ def chars
20
+ 'abcdefghijklmnopqrstuvwxyz'.split('').shuffle
21
+ end
22
22
 
23
- def adjectives
24
- @adjectives ||= get_wordlist('adjectives')
25
- end
23
+ def adjectives
24
+ @adjectives ||= get_wordlist('adjectives')
25
+ end
26
26
 
27
- def nouns
28
- @nouns ||= get_wordlist('nouns')
29
- end
27
+ def nouns
28
+ @nouns ||= get_wordlist('nouns')
29
+ end
30
30
 
31
- def symbols
32
- '!#$%&()*+,-=./:;<?>@[\]^_'.split('')
33
- end
31
+ def symbols
32
+ '!#$%&()*+,-=./:;<?>@[\]^_'.split('')
33
+ end
34
34
 
35
- def digits
36
- '123456789'.split('')
35
+ def digits
36
+ '123456789'.split('')
37
+ end
37
38
  end
38
- end
39
39
  end
@@ -0,0 +1,3 @@
1
+ module Patter
2
+ VERSION = "1.0.6"
3
+ end
data/lib/patter.rb CHANGED
@@ -5,3 +5,4 @@ require_relative 'patter/source_provider'
5
5
  require_relative 'patter/source'
6
6
  require_relative 'patter/pattern'
7
7
  require_relative 'patter/sample'
8
+ require_relative 'patter/version'
data/words/adjectives.txt CHANGED
@@ -92,12 +92,9 @@ better
92
92
  best
93
93
  bewitched
94
94
  big
95
- big-hearted
96
95
  biodegradable
97
- bite-sized
98
96
  bitter
99
97
  black
100
- black-and-white
101
98
  bland
102
99
  blank
103
100
  blaring
@@ -160,7 +157,6 @@ circular
160
157
  classic
161
158
  clean
162
159
  clear
163
- clear-cut
164
160
  clever
165
161
  close
166
162
  closed
@@ -299,7 +295,6 @@ eager
299
295
  earnest
300
296
  early
301
297
  easy
302
- easy-going
303
298
  ecstatic
304
299
  edible
305
300
  educated
@@ -348,8 +343,6 @@ experienced
348
343
  expert
349
344
  extraneous
350
345
  extroverted
351
- extra-large
352
- extra-small
353
346
  fabulous
354
347
  failing
355
348
  faint
@@ -363,8 +356,6 @@ fancy
363
356
  fantastic
364
357
  far
365
358
  faraway
366
- far-flung
367
- far-off
368
359
  fast
369
360
  fat
370
361
  fatal
@@ -460,7 +451,6 @@ glossy
460
451
  glum
461
452
  golden
462
453
  good
463
- good-natured
464
454
  gorgeous
465
455
  graceful
466
456
  gracious
@@ -497,9 +487,7 @@ handmade
497
487
  handsome
498
488
  handy
499
489
  happy
500
- happy-go-lucky
501
490
  hard
502
- hard-to-find
503
491
  harmful
504
492
  harmless
505
493
  harmonious
@@ -518,7 +506,6 @@ helpless
518
506
  hidden
519
507
  hideous
520
508
  high
521
- high-level
522
509
  hilarious
523
510
  hoarse
524
511
  hollow
@@ -549,8 +536,6 @@ idolized
549
536
  ignorant
550
537
  ill
551
538
  illegal
552
- ill-fated
553
- ill-informed
554
539
  illiterate
555
540
  illustrious
556
541
  imaginary
@@ -608,7 +593,6 @@ irritating
608
593
  itchy
609
594
  jaded
610
595
  jagged
611
- jam-packed
612
596
  jaunty
613
597
  jealous
614
598
  jittery
@@ -671,7 +655,6 @@ loathsome
671
655
  lone
672
656
  lonely
673
657
  long
674
- long-term
675
658
  loose
676
659
  lopsided
677
660
  lost
@@ -688,7 +671,6 @@ lumpy
688
671
  lustrous
689
672
  luxurious
690
673
  mad
691
- made-up
692
674
  magnificent
693
675
  majestic
694
676
  major
@@ -792,7 +774,6 @@ offbeat
792
774
  offensive
793
775
  official
794
776
  old
795
- old-fashioned
796
777
  only
797
778
  open
798
779
  optimal
@@ -904,7 +885,6 @@ queasy
904
885
  querulous
905
886
  questionable
906
887
  quick
907
- quick-witted
908
888
  quiet
909
889
  quintessential
910
890
  quirky
@@ -981,10 +961,7 @@ scratchy
981
961
  scrawny
982
962
  second
983
963
  secondary
984
- second-hand
985
964
  secret
986
- self-assured
987
- self-reliant
988
965
  selfish
989
966
  sentimental
990
967
  separate
@@ -1006,7 +983,6 @@ shocked
1006
983
  shocking
1007
984
  shoddy
1008
985
  short
1009
- short-term
1010
986
  showy
1011
987
  shrill
1012
988
  shy
@@ -1111,7 +1087,6 @@ superb
1111
1087
  superficial
1112
1088
  superior
1113
1089
  supportive
1114
- sure-footed
1115
1090
  surprised
1116
1091
  suspicious
1117
1092
  svelte
@@ -1285,14 +1260,6 @@ weepy
1285
1260
  weighty
1286
1261
  weird
1287
1262
  welcome
1288
- well-documented
1289
- well-groomed
1290
- well-informed
1291
- well-lit
1292
- well-made
1293
- well-off
1294
- well-to-do
1295
- well-worn
1296
1263
  wet
1297
1264
  which
1298
1265
  whimsical
@@ -1303,7 +1270,6 @@ whole
1303
1270
  whopping
1304
1271
  wicked
1305
1272
  wide
1306
- wide-eyed
1307
1273
  wiggly
1308
1274
  wild
1309
1275
  willing
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - crdx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-04 00:00:00.000000000 Z
11
+ date: 2019-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -65,6 +65,7 @@ files:
65
65
  - lib/patter/sample.rb
66
66
  - lib/patter/source.rb
67
67
  - lib/patter/source_provider.rb
68
+ - lib/patter/version.rb
68
69
  - words/adjectives.txt
69
70
  - words/nouns.txt
70
71
  homepage: https://github.com/crdx/patter
@@ -89,5 +90,5 @@ requirements: []
89
90
  rubygems_version: 3.0.4
90
91
  signing_key:
91
92
  specification_version: 4
92
- summary: Patterns.
93
+ summary: Generate strings from patterns.
93
94
  test_files: []