ipsumizer 0.1.0 → 0.2.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
- SHA1:
3
- metadata.gz: '084cbabf13cf81e3d22e97c28eeab3d7f7f333a3'
4
- data.tar.gz: e297906ad93aa5b31392801cbe43d089c2cfd28d
2
+ SHA256:
3
+ metadata.gz: b909665eb8e7ea3d19820223a9aaa0d4c48a5bba6057930d3affce02ae79d54d
4
+ data.tar.gz: ccf35e34d0a895d043d2b4341eb5f1cca1ab91c66c830ab9f56b34e2395672ec
5
5
  SHA512:
6
- metadata.gz: f38a89bc38a7fe5c7ede90f706ca58a9ca4f05e5ad965427783283e9293c26ca390603c43767f7c54549ef384fa38a5cecbe9bdee01d17f9efae598ffa8408de
7
- data.tar.gz: 5a0fb3fb60e1ac1c0b7c88d7b5f9c1f6342976b174153164aee39ea61f4faa74764e2e8f1c502d56af4fb4299e83802fc380b9a5f859d99ad5fa78cd1aa086c1
6
+ metadata.gz: 00b356c6221db16ea74a0b29e2557de52948c13cd0b6252e3be7df933213487ed31f70da81ba499a0aae3eb19364c955acd970b47c5e1e28a3581fd1fdfb1453
7
+ data.tar.gz: 1fd1a4dd716d43936d57f317be2dbe3593d852484fa04c359eb215995c481a940f3f4ff41ea23b2bb6a5ef806430e61146e802f837166692e8be67ae060a84a2
@@ -0,0 +1,21 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ ruby: ["3.0", "3.1", "3.2", "3.3", "3.4"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ bundler-cache: true
21
+ - run: bundle exec rake test
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
11
+ .byebug_history
data/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.2.0] - 2026-11-28
9
+
10
+ ### Changed
11
+
12
+ - Require Ruby >= 3.0
13
+ - Replace Travis CI (Ruby 2.0) with GitHub Actions testing Ruby 3.0 through 3.4
14
+ - Modernize gemspec: bundler `~> 2.0`, rake `~> 13.0`, minitest `~> 5.0`; add gem metadata URIs
15
+ - Collapse runs of internal whitespace to a single space during normalization
16
+ - Error message for invalid prefix now reads "must be positive" (previously "non-negative")
17
+
18
+ ### Fixed
19
+
20
+ - `prefix:` option no longer crashes when given a non-integer value such as a string (e.g. `prefix: "2"`); it is coerced with `to_i` before validation
21
+
22
+ ### Removed
23
+
24
+ - Development dependency on byebug (bin/console uses IRB)
25
+ - Stray build artifacts from the working tree (`*.gem`, `.byebug_history`, `Gemfile.lock`); now covered by `.gitignore`
26
+
27
+ ### Internal
28
+
29
+ - Add `# frozen_string_literal: true`; use `raise` instead of `fail`; use `%r{}` literal and `Hash.new(0)` counters in `lib/ipsumizer.rb`
30
+ - Tests use `assert_raises` instead of begin/rescue; added coverage for string prefixes and whitespace normalization
31
+
32
+ ## [0.1.0] - 2017-12-10
33
+
34
+ ### Added
35
+
36
+ - Initial release: character-level language model with `speak`, `sentence`, configurable `prefix` and `sentencer`
data/README.md CHANGED
@@ -120,10 +120,6 @@ Or install it yourself as:
120
120
 
121
121
  $ gem install ipsumizer
122
122
 
123
- ## Usage
124
-
125
- TODO: Write usage instructions here
126
-
127
123
  ## Development
128
124
 
129
125
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/ipsumizer.gemspec CHANGED
@@ -10,17 +10,22 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["dfhoughton@gmail.com"]
11
11
 
12
12
  spec.summary = 'Generate lorem ipsum text from a text sample.'
13
- spec.description = spec.summary
13
+ spec.description = 'Ipsumizer builds a character-level language model from sample sentences and generates random sentences that resemble the original text.'
14
14
  spec.homepage = "https://github.com/dfhoughton/ipsumizer"
15
15
  spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 3.0"
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
19
  spec.bindir = "exe"
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
21
  spec.require_paths = ["lib"]
21
22
 
22
- spec.add_development_dependency "bundler", "~> 1.10"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "minitest", "~> 5"
25
- spec.add_development_dependency "byebug", "~> 0"
23
+ spec.metadata = {
24
+ "homepage_uri" => spec.homepage,
25
+ "changelog_uri" => "#{spec.homepage}/blob/master/CHANGELOG.md"
26
+ }
27
+
28
+ spec.add_development_dependency "bundler", "~> 2.0"
29
+ spec.add_development_dependency "rake", "~> 13.0"
30
+ spec.add_development_dependency "minitest", "~> 5.0"
26
31
  end
@@ -1,3 +1,3 @@
1
1
  class Ipsumizer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/ipsumizer.rb CHANGED
@@ -1,70 +1,61 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "ipsumizer/version"
2
4
 
3
5
  class Ipsumizer
4
6
  attr_reader :prefix, :sentencer
5
7
 
6
- DEFAULT_SENTENCER = Regexp.new %r{([.!?][.!?\p{Final_Punctuation}\p{Close_Punctuation}"\s]*)}
8
+ DEFAULT_SENTENCER = %r{([.!?][.!?\p{Final_Punctuation}\p{Close_Punctuation}"\s]*)}
7
9
 
8
10
  DEFAULT_PREFIX = 4
9
11
 
10
- def initialize( sentences, prefix: DEFAULT_PREFIX, sentencer: DEFAULT_SENTENCER )
12
+ def initialize(sentences, prefix: DEFAULT_PREFIX, sentencer: DEFAULT_SENTENCER)
11
13
  @prefix = prefix.to_i
12
- fail "prefix length must be non-negative: #{prefix}" unless prefix > 0
14
+ raise "prefix length must be positive: #{prefix}" unless @prefix > 0
13
15
  @sentencer = sentencer
14
16
  @transitions = {}
15
- if sentences.is_a? String
16
- sentences = sentence sentences
17
- end
18
- sentences = sentences.map{ |s| s.strip.gsub /\s/, ' ' }.select{ |s| s =~ /\S/ }
19
- fail "no sentences" unless sentences.any?
17
+ sentences = sentence(sentences) if sentences.is_a? String
18
+ sentences = sentences.map { |s| s.strip.gsub(/\s+/, ' ') }.select { |s| s =~ /\S/ }
19
+ raise "no sentences" unless sentences.any?
20
20
  sentences.each do |s|
21
- key = ''
22
- i = 0
21
+ key = +''
23
22
  (0..s.length).each do |i|
24
- nxt = if i == s.length
25
- nil
26
- else
27
- s[i]
28
- end
29
- counts = @transitions[key] ||= {}
30
- counts[nxt] = counts[nxt].to_i + 1
23
+ nxt = i == s.length ? nil : s[i]
24
+ counts = (@transitions[key] ||= Hash.new(0))
25
+ counts[nxt] += 1
31
26
  if nxt
32
27
  key += nxt
33
- if key.length > prefix
34
- key = key[1..-1]
35
- end
28
+ key = key[1..] if key.length > @prefix
36
29
  end
37
30
  end
38
31
  end
39
32
  @transitions.each do |pfx, counts|
40
- total = counts.values.reduce(:+)
41
- probabilities = counts.values.map{ |n| n.to_r / total }
42
- @transitions[pfx] = AliasTable.new( counts.keys, probabilities )
33
+ total = counts.values.sum
34
+ probabilities = counts.values.map { |n| n.to_r / total }
35
+ @transitions[pfx] = AliasTable.new(counts.keys, probabilities)
43
36
  end
44
37
  end
45
38
 
46
- # split a text into sentences, where sentences are separated by on of '.', '!', and '?', optionally preceded by
39
+ # Split a text into sentences, where sentences are separated by one of '.', '!', and '?', optionally followed by
47
40
  # double quotes or closing brackets and so forth
48
41
  def sentence(text)
49
- text.split(sentencer).each_slice(2).map{ |*bits| bits.join }.select{ |s| s =~ /\S/ }
42
+ text.split(sentencer).each_slice(2).map { |*bits| bits.join }.select { |s| s =~ /\S/ }
50
43
  end
51
44
 
52
- # make a random sentence
45
+ # Generate a random sentence
53
46
  def speak
54
- pfx = s = ''
47
+ pfx = s = +''
55
48
  loop do
56
49
  nxt = @transitions[pfx]&.generate
57
50
  break unless nxt
58
51
  s += nxt
59
52
  pfx += nxt
60
- if pfx.length > prefix
61
- pfx = pfx[1..-1]
62
- end
53
+ pfx = pfx[1..] if pfx.length > prefix
63
54
  end
64
55
  s
65
56
  end
66
57
 
67
- # copied in here and fixed because the gem was in a broken state
58
+ # Copied in here and fixed because the gem was in a broken state
68
59
  class AliasTable
69
60
  def initialize(x_set, p_value)
70
61
  @p_primary = p_value.map(&:to_r)
@@ -84,8 +75,10 @@ class Ipsumizer
84
75
  @alias[deficit] = @x[surplus]
85
76
  if @p_primary[surplus] == parity
86
77
  @p_primary[surplus] = Rational(1)
78
+ elsif @p_primary[surplus] < parity
79
+ deficit_set << surplus
87
80
  else
88
- (@p_primary[surplus] < parity ? deficit_set : surplus_set) << surplus
81
+ surplus_set << surplus
89
82
  end
90
83
  end
91
84
  end
@@ -95,5 +88,4 @@ class Ipsumizer
95
88
  rand <= @p_primary[column] ? @x[column] : @alias[column]
96
89
  end
97
90
  end
98
-
99
91
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipsumizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dfhoughton
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2017-12-11 00:00:00.000000000 Z
10
+ date: 2026-11-28 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -16,65 +15,53 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '1.10'
18
+ version: '2.0'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '1.10'
25
+ version: '2.0'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '10.0'
32
+ version: '13.0'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '10.0'
39
+ version: '13.0'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: minitest
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '5'
46
+ version: '5.0'
48
47
  type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '5'
55
- - !ruby/object:Gem::Dependency
56
- name: byebug
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- description: Generate lorem ipsum text from a text sample.
53
+ version: '5.0'
54
+ description: Ipsumizer builds a character-level language model from sample sentences
55
+ and generates random sentences that resemble the original text.
70
56
  email:
71
57
  - dfhoughton@gmail.com
72
58
  executables: []
73
59
  extensions: []
74
60
  extra_rdoc_files: []
75
61
  files:
62
+ - ".github/workflows/ci.yml"
76
63
  - ".gitignore"
77
- - ".travis.yml"
64
+ - CHANGELOG.md
78
65
  - Gemfile
79
66
  - LICENSE.txt
80
67
  - README.md
@@ -87,8 +74,9 @@ files:
87
74
  homepage: https://github.com/dfhoughton/ipsumizer
88
75
  licenses:
89
76
  - MIT
90
- metadata: {}
91
- post_install_message:
77
+ metadata:
78
+ homepage_uri: https://github.com/dfhoughton/ipsumizer
79
+ changelog_uri: https://github.com/dfhoughton/ipsumizer/blob/master/CHANGELOG.md
92
80
  rdoc_options: []
93
81
  require_paths:
94
82
  - lib
@@ -96,16 +84,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
84
  requirements:
97
85
  - - ">="
98
86
  - !ruby/object:Gem::Version
99
- version: '0'
87
+ version: '3.0'
100
88
  required_rubygems_version: !ruby/object:Gem::Requirement
101
89
  requirements:
102
90
  - - ">="
103
91
  - !ruby/object:Gem::Version
104
92
  version: '0'
105
93
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.6.13
108
- signing_key:
94
+ rubygems_version: 3.6.2
109
95
  specification_version: 4
110
96
  summary: Generate lorem ipsum text from a text sample.
111
97
  test_files: []
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- before_install: gem install bundler -v 1.10.6