glueckskeks 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e93c37db90c6c6781039772984d307f7d08bba57
4
- data.tar.gz: ad4e2488db8b3b997c52483f010f416593ef12c4
3
+ metadata.gz: c8d596fe9089e8325ffdda0c275925c96df62946
4
+ data.tar.gz: e76338be2e23856908d413b9a2528c5a2a753dcf
5
5
  SHA512:
6
- metadata.gz: d7580e504738e58ce6c4b2c06c3b26b67aa43bc3ac57d180bf2c058f67e4d1d77b3ec07e887e99b72c47b5204554a826bbcceb5e8adfdcfaca15d4e6fc863efa
7
- data.tar.gz: 82eeac598a5e75e8708831617544ba3c244bb161e89d00e420a515a27b11128c88353e83688085bb7d1180d746b90f74035dcd3548e678d3992b1c5cb385dbd4
6
+ metadata.gz: 91215a0d6b09e922b73d9d7b6106868e48a09795624453c05fd2c2c759cfabe6d3228f64fec859100d7722595ed769a8e6692d1cd690d256184feb387775916c
7
+ data.tar.gz: d984b3216a4b6c19fff24fb31d03ac6f034517cefb424db94f5b5383cf9f59c4788ab0946c9d013207ba4933bffe7b665662a0959013469cad4a25b8b96ea59d
data/.gitignore CHANGED
@@ -7,4 +7,3 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- /corpus
data/README.md CHANGED
@@ -12,7 +12,7 @@ To install the gem (to use its executable):
12
12
 
13
13
  $ gem install glueckskeks
14
14
 
15
- To play with its functionality from your own (ruby) code dd this line to your application's Gemfile:
15
+ To play with its functionality from your own (ruby) code add this line to your application's Gemfile:
16
16
 
17
17
  ```ruby
18
18
  gem 'glueckskeks'
data/exe/glueckskeks CHANGED
@@ -3,16 +3,22 @@
3
3
  require 'glueckskeks'
4
4
  require 'optparse'
5
5
 
6
- options = {}
6
+ options = {corpus: 'corpus', base: 'base'}
7
7
 
8
8
  optparse = OptionParser.new do |opts|
9
9
  opts.banner = "Usage: #{$PROGRAM_NAME}"
10
10
  opts.separator ""
11
- opts.separator "Generate phrase from files in corpus/."
11
+ opts.separator "Generate phrase from files (default: in corpus/)."
12
12
  opts.separator ""
13
13
 
14
- opts.on('-d', '--debug', 'Print debug messages to STDOUT') do |o|
15
- options[:debug] = o
14
+ opts.on('-b', '--base=BASE', 'Start extension from BASE file (default: \'base\')') do |b|
15
+ options[:base] = b
16
+ end
17
+ opts.on('-c', '--corpus=DIRECTORY', 'Read .corpus files from DIRECTORY (default: \'./corpus\'') do |c|
18
+ options[:corpus] = c
19
+ end
20
+ opts.on('-d', '--debug', 'Print debug messages to STDOUT') do |d|
21
+ options[:debug] = d
16
22
  end
17
23
  opts.on_tail('--version', 'Show version and exit.') do
18
24
  puts "#{$PROGRAM_NAME} #{Glueckskeks::VERSION}"
@@ -26,6 +32,6 @@ end.parse!
26
32
 
27
33
  Glueckskeks.logger.level = options[:debug] ? Logger::DEBUG : Logger::INFO
28
34
 
29
- phrase = Glueckskeks.generate
35
+ phrase = Glueckskeks.generate(options[:corpus], options[:base])
30
36
  puts phrase
31
37
  puts Glueckskeks::Collapser.collapse(phrase)
data/lib/glueckskeks.rb CHANGED
@@ -16,16 +16,16 @@ module Glueckskeks
16
16
  @logger = new_logger
17
17
  end
18
18
 
19
- def self.generate
20
- @corpus = CorpusReader.read_corpus_files
21
- if @corpus&.empty?
19
+ def self.generate(corpus_dir='corpus', entry='base')
20
+ @corpus = CorpusReader.read_corpus_files(corpus_dir)
21
+ if @corpus && @corpus.empty?
22
22
  STDERR.puts "Empty corpus, are any data files present in ./corpus ?"
23
23
  exit 1
24
24
  end
25
- if @corpus['base'].nil? || @corpus['base'].empty?
25
+ if @corpus[entry].nil? || @corpus[entry].empty?
26
26
  STDERR.puts "Corpus does not contain a base (corpus/base.corpus) file, or it does not contain any patterns."
27
27
  exit 2
28
28
  end
29
- Templater.fill(@corpus['base'].sample, @corpus)
29
+ Templater.fill(@corpus[entry].sample, @corpus)
30
30
  end
31
31
  end
@@ -1,9 +1,9 @@
1
1
  module Glueckskeks
2
2
  class CorpusReader
3
- def self.read_corpus_files
3
+ def self.read_corpus_files(corpus_dir='corpus')
4
4
  result_map = {}
5
5
 
6
- Dir.glob('corpus/*.corpus').each do |filename|
6
+ Dir.glob("#{corpus_dir}/*.corpus").each do |filename|
7
7
  Glueckskeks.logger.debug "Reading corpus file #{filename}"
8
8
  file = File.new(filename)
9
9
 
@@ -13,6 +13,9 @@ module Glueckskeks
13
13
  lines.reject!(&:empty?)
14
14
 
15
15
  Glueckskeks.logger.debug "#{lines.count} valid line(s) found"
16
+ if lines.count == 0
17
+ Glueckskeks.logger.error "#{filename} does not contain any pattern"
18
+ end
16
19
  result_map[File.basename(file, '.corpus')] = lines
17
20
  end
18
21
 
@@ -3,6 +3,9 @@ module Glueckskeks
3
3
  def self.replace(str, corpus)
4
4
  /.*<(?<type>[^>]*)>.*/ =~ str
5
5
  if type
6
+ if !(corpus.has_key? type)
7
+ Glueckskeks.logger.error "No corpus entry for #{type} found"
8
+ end
6
9
  replace_with = corpus[type].sample
7
10
  str.gsub!("\<#{type}\>", replace_with)
8
11
  end
@@ -1,3 +1,3 @@
1
1
  module Glueckskeks
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glueckskeks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Wolfsteller