hiq 0.2.1 → 0.2.2
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 +4 -4
- data/lib/hiq/domain/filler_library.rb +47 -0
- data/lib/hiq/domain/line_composer.rb +7 -32
- data/lib/hiq/haiku.rb +3 -1
- data/lib/hiq/version.rb +1 -1
- data/lib/hiq.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1796d2469d18b061387e2eaf777827913a4fd856e5b16a1111c9b43b7f059801
|
4
|
+
data.tar.gz: 398d2dd88d26300acd27e8ed3c60501c7ca2cd7a146bb4b9e472551f35447ca1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60fb47db7e6d8643e12c3ec7ae218cfedfec1a6bba2c5209ef8eded433f28c7896be84cca2fa69dcbca3e6aa0e1f8e0ffe0dbe1cf9b6e6e9e75716eccc4612c6
|
7
|
+
data.tar.gz: 4da0e7a06d9544103bb0013d737ffe95eadc522ba77f780fbbffd60acafe6c6545d50ae40bb150b29424cf008cac1a3b2899cd8d5485e856c806ea1abc387544
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hiq
|
4
|
+
# Provided of filler for lines of haiku
|
5
|
+
class FillerLibrary
|
6
|
+
def self.interpolated_fillers
|
7
|
+
{
|
8
|
+
5 => {
|
9
|
+
1 => 'the X',
|
10
|
+
2 => 'ghastly X',
|
11
|
+
3 => 'shadow of X',
|
12
|
+
4 => 'X of my joy fade'
|
13
|
+
},
|
14
|
+
7 => {
|
15
|
+
1 => 'a X',
|
16
|
+
2 => 'the pale X',
|
17
|
+
3 => 'X in silence',
|
18
|
+
4 => 'X ends the autumn',
|
19
|
+
5 => 'A spark of X above',
|
20
|
+
6 => 'the sad facade of X torn'
|
21
|
+
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.fillers
|
26
|
+
{
|
27
|
+
5 => ['empty riverside', 'tears flow in the rain', 'cheerful summer\'s charm'].shuffle,
|
28
|
+
7 => ['the vain wind of summer blows', 'gentle breeze upon a mountain', 'a frog jumps into a well'].shuffle
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :ifillers, :cfillers
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@ifillers = FillerLibrary.interpolated_fillers
|
36
|
+
@cfillers = FillerLibrary.fillers
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_const_filler(syllable_length)
|
40
|
+
cfillers[syllable_length].shift
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_interpolated_filler(syllable_length, gap_size)
|
44
|
+
ifillers[syllable_length][gap_size]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -5,15 +5,16 @@ module Hiq
|
|
5
5
|
class LineComposer
|
6
6
|
include Syllabizable
|
7
7
|
|
8
|
-
attr_reader :line, :target_syllable_length
|
8
|
+
attr_reader :line, :target_syllable_length, :library
|
9
9
|
|
10
|
-
def self.call(line, target_syllable_length:)
|
11
|
-
new(line, target_syllable_length: target_syllable_length).call
|
10
|
+
def self.call(line, target_syllable_length:, library:)
|
11
|
+
new(line, target_syllable_length: target_syllable_length, library: library).call
|
12
12
|
end
|
13
13
|
|
14
|
-
def initialize(line, target_syllable_length:)
|
14
|
+
def initialize(line, target_syllable_length:, library:)
|
15
15
|
@line = line
|
16
16
|
@target_syllable_length = target_syllable_length
|
17
|
+
@library = library
|
17
18
|
end
|
18
19
|
|
19
20
|
def call
|
@@ -29,35 +30,9 @@ module Hiq
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def filled_line
|
32
|
-
return [
|
33
|
+
return [library.get_const_filler(target_syllable_length)] if line.empty?
|
33
34
|
|
34
|
-
[
|
35
|
-
end
|
36
|
-
|
37
|
-
def interpolated_fillers
|
38
|
-
{
|
39
|
-
5 => {
|
40
|
-
1 => 'the X',
|
41
|
-
2 => 'ghastly X',
|
42
|
-
3 => 'shadow of X',
|
43
|
-
4 => 'X of my joy fade'
|
44
|
-
},
|
45
|
-
7 => {
|
46
|
-
1 => 'a X',
|
47
|
-
2 => 'the pale X',
|
48
|
-
3 => 'X in silence',
|
49
|
-
4 => 'X ends the autumn',
|
50
|
-
5 => 'A spark of X above',
|
51
|
-
6 => 'the sad facade of X torn'
|
52
|
-
}
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
def fillers
|
57
|
-
{
|
58
|
-
5 => ['empty riverside', 'tears flow in the rain', 'cheerful summer\'s charm'],
|
59
|
-
7 => ['the vain wind of summer blows', 'gentle breeze upon a mountain', 'a frog jumps into a well']
|
60
|
-
}
|
35
|
+
[library.get_interpolated_filler(target_syllable_length, syllable_gap_size).gsub('X', line.first)]
|
61
36
|
end
|
62
37
|
end
|
63
38
|
end
|
data/lib/hiq/haiku.rb
CHANGED
@@ -20,8 +20,10 @@ module Hiq
|
|
20
20
|
def haiku_lines
|
21
21
|
WordChecker.validate!(words)
|
22
22
|
|
23
|
+
library = FillerLibrary.new
|
24
|
+
|
23
25
|
[5, 7, 5].zip(line_templates).map do |syllabes, line|
|
24
|
-
LineComposer.call(line, target_syllable_length: syllabes)
|
26
|
+
LineComposer.call(line, target_syllable_length: syllabes, library: library)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
data/lib/hiq/version.rb
CHANGED
data/lib/hiq.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Taras
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -87,6 +87,7 @@ extensions: []
|
|
87
87
|
extra_rdoc_files: []
|
88
88
|
files:
|
89
89
|
- lib/hiq.rb
|
90
|
+
- lib/hiq/domain/filler_library.rb
|
90
91
|
- lib/hiq/domain/line_composer.rb
|
91
92
|
- lib/hiq/domain/word_checker.rb
|
92
93
|
- lib/hiq/exceptions.rb
|