ssmd 0.3.1 → 0.4.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: ca958be00bb04e7af41269615ad89353790aff56
4
- data.tar.gz: f97eaddda402d1ab60c1e5b30b72495d7cdfbc61
3
+ metadata.gz: 7bf70e02b121cec8728e59ae56a22e8a96024336
4
+ data.tar.gz: '00582115495e3b0ccc088f5c268cd367e0602630'
5
5
  SHA512:
6
- metadata.gz: 9a59de6e3c716e227e08b1c5804c57f149ef320dad4b4cc00582bc65a7a1642ec3ad93e9642e1289bac8723a92151c984a433ed43c74ac285ae85e71d43e361b
7
- data.tar.gz: a368ceb07a06342ffa5a92b3d44ed77d078d943064dc51a825ff3064d32f2b4b123a46000033711a7822a70b0d9ac9dc64ffe0670dac6b42065cd4cca745d23f
6
+ metadata.gz: f8cfcf7f8f4c809a980970b2e5c9380d7ec798263352896fa27203be998eb4d1cd4a3c57891d7c5e8e257ae76251d29bce00658896cf6df274aa261d03786f33
7
+ data.tar.gz: 65aadce5e10d597d1d1c14eca36bd843ad6092f3342910915d5bcf10faca47d751c0f9c0da5763f2e105d4a5c8e0a10ca3c0451f91a6c47d9162d95e89efaf25
data/README.md CHANGED
@@ -48,6 +48,8 @@ described in the specification are implemented:
48
48
  * Mark
49
49
  * Language
50
50
  * Phoneme
51
+ * Prosody
52
+ * Paragraph
51
53
 
52
54
  ## Development
53
55
 
data/SPECIFICATION.md CHANGED
@@ -133,12 +133,14 @@ First prepare the ingredients.
133
133
  Don't forget to wash them first.
134
134
 
135
135
  Lastly mix them all together.
136
+
137
+ Don't forget to do the dishes after!
136
138
  ```
137
139
 
138
140
  SSML:
139
141
  ```html
140
- <p>First prepare the ingredients. Don't forget to wash them first.</p>
141
- <p>Lastly mix them all together.</p>
142
+ <p>First prepare the ingredients.
143
+ Don't forget to wash them first.</p><p>Lastly mix them all together.</p><p>Don't forget to do the dishes after!</p>
142
144
  ```
143
145
 
144
146
  ***
@@ -4,8 +4,12 @@ module SSMD
4
4
  class Converter
5
5
  attr_reader :input
6
6
 
7
- def initialize(input)
7
+ def initialize(input, skip: [])
8
8
  @input = input
9
+
10
+ processors.delete_if do |processor|
11
+ Array(skip).any? { |name| processor.name =~ /\ASSMD::Processors::#{name}Processor\Z/i }
12
+ end
9
13
  end
10
14
 
11
15
  def convert
@@ -23,12 +27,14 @@ module SSMD
23
27
  end
24
28
 
25
29
  def processors
26
- p = SSMD::Processors
30
+ @processors ||= begin
31
+ p = SSMD::Processors
27
32
 
28
- [
29
- p::EmphasisProcessor, p::AnnotationProcessor, p::MarkProcessor,
30
- p::ProsodyProcessor
31
- ]
33
+ [
34
+ p::EmphasisProcessor, p::AnnotationProcessor, p::MarkProcessor,
35
+ p::ProsodyProcessor, p::ParagraphProcessor
36
+ ]
37
+ end
32
38
  end
33
39
 
34
40
  def process(processor, input, strip: false)
@@ -0,0 +1,21 @@
1
+ require_relative 'processor'
2
+
3
+ module SSMD::Processors
4
+ class ParagraphProcessor < Processor
5
+ def result
6
+ "<p>" + match.string.gsub(regex, "</p><p>") + "</p>"
7
+ end
8
+
9
+ def regex
10
+ /\n\n+/
11
+ end
12
+
13
+ def substitute(input)
14
+ result if match
15
+ end
16
+
17
+ def strip_ssmd(input)
18
+ input.gsub(regex, "\n") if match
19
+ end
20
+ end
21
+ end
@@ -7,7 +7,7 @@ module SSMD::Processors
7
7
  end
8
8
 
9
9
  def regex
10
- Regex.prosody
10
+ @regex ||= Regex.prosody
11
11
  end
12
12
 
13
13
  private
@@ -7,3 +7,4 @@ require 'ssmd/processors/annotation_processor'
7
7
  require 'ssmd/processors/emphasis_processor'
8
8
  require 'ssmd/processors/mark_processor'
9
9
  require 'ssmd/processors/prosody_processor'
10
+ require 'ssmd/processors/paragraph_processor'
data/lib/ssmd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SSMD
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/ssmd.rb CHANGED
@@ -4,17 +4,27 @@ require "ssmd/converter"
4
4
  module SSMD
5
5
  module_function
6
6
 
7
- def to_ssml(ssmd)
8
- Converter.new(ssmd).convert
7
+ ##
8
+ # Translates the given SSMD text to SSML.
9
+ #
10
+ # @param ssmd [String] The SSMD markup to be converted to SSML
11
+ # @param skip [Array<Symbol>] Formats (e.g. `:paragraph`, `:prosody`) to skip.
12
+ #
13
+ # @return [String] Resulting SSML
14
+ def to_ssml(ssmd, skip: [])
15
+ Converter.new(ssmd, skip: skip).convert
9
16
  end
10
17
 
11
18
  ##
12
19
  # Returns the given string without any SSMD annotations.
13
20
  # For instance for `hello *world*` would return `hello world`.
14
21
  #
22
+ # @param ssmd [String] The SSMD markup to strip from SSMD annotations.
23
+ # @param skip [Array<Symbol>] Formats (e.g. `:paragraph`, `:prosody`) to skip.
24
+ #
15
25
  # @return [String]
16
- def strip_ssmd(ssmd)
17
- Converter.new(ssmd).strip
26
+ def strip_ssmd(ssmd, skip: [])
27
+ Converter.new(ssmd, skip: skip).strip
18
28
  end
19
29
 
20
30
  def root_dir
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Kahl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-15 00:00:00.000000000 Z
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -116,6 +116,7 @@ files:
116
116
  - lib/ssmd/processors/annotation_processor.rb
117
117
  - lib/ssmd/processors/emphasis_processor.rb
118
118
  - lib/ssmd/processors/mark_processor.rb
119
+ - lib/ssmd/processors/paragraph_processor.rb
119
120
  - lib/ssmd/processors/processor.rb
120
121
  - lib/ssmd/processors/prosody_processor.rb
121
122
  - lib/ssmd/version.rb