gvg 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f47f75b60baca60b13e88df869bf4f1b01579167227964898600188f309d20e4
4
+ data.tar.gz: 4ef10073575fd286280b00e8458287f7f722c6f67afc07d6b15b51e6ddc6a29f
5
+ SHA512:
6
+ metadata.gz: aa7859e011ed1467ade107a253e9d763a6aca0276f02c61248d1a102b8819f1db6a1e540840ac55b1a6a195571c4b5f7ff21bb1d7de7b04b27d0706972e02244
7
+ data.tar.gz: e1aa961e285ee9f62bd21e6d8b68f77eb4d63947248dc5bc45808bacd3c93ac0ac0d984bd712dbe1922260bdeca8bf757d5f8d90571bb183f78d4f1a795cc135
data/bin/gvg ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gvg'
4
+
5
+ Gvg::Cli.start(ARGV)
@@ -0,0 +1,7 @@
1
+ class Gvg
2
+ end
3
+
4
+ require 'gvg/agnot'
5
+ require 'gvg/cli'
6
+ require 'gvg/hello'
7
+ require 'gvg/parser'
@@ -0,0 +1,64 @@
1
+ require 'aasm'
2
+ require 'nokogiri'
3
+
4
+ def audio(audio)
5
+ parent = @builder.doc.at('vxml')
6
+ builder = Nokogiri::XML::Builder.with(parent) do |xml|
7
+ xml.block do
8
+ xml.prompt do
9
+ xml.audio(src: audio['source']) do
10
+ xml.text(audio['text'])
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ return builder.to_xml
17
+ end
18
+
19
+ def open
20
+ @builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
21
+ xml.vxml(version: 2.0, lang: 'en')
22
+ end
23
+ end
24
+
25
+ def close
26
+ puts @builder.to_xml
27
+ end
28
+
29
+ class Gvg::Agnot
30
+ include AASM
31
+
32
+ aasm whiny_transitions: false do
33
+ state :waiting, initial: true
34
+ state :saying, :listening, :working
35
+ state :done
36
+
37
+ event :start do
38
+ transitions to: :waiting, after: Proc.new {|*args| open(*args)}
39
+ end
40
+
41
+ event :stop do
42
+ transitions to: :done, after: Proc.new {|*args| close(*args)}
43
+ end
44
+
45
+ event :say do
46
+ transitions from: :waiting, to: :saying, after: Proc.new {|*args| audio(*args)}
47
+ transitions from: :listening, to: :saying, after: Proc.new {|*args| audio(*args)}
48
+ transitions from: :saying, to: :saying, after: Proc.new {|*args| audio(*args)}
49
+ end
50
+
51
+ event :listen do
52
+ transitions from: :saying, to: :listening
53
+ end
54
+
55
+ event :work do
56
+ transitions from: :listening, to: :working
57
+ end
58
+
59
+ event :wait do
60
+ transitions from: [:saying, :listening, :working], to: :waiting
61
+ end
62
+ end
63
+ end
64
+
@@ -0,0 +1,35 @@
1
+ require 'gvg'
2
+ require 'thor'
3
+
4
+ def resource_path
5
+ File.join(File.dirname(File.expand_path(__FILE__)), '../../resources')
6
+ end
7
+
8
+ class Gvg::Cli < Thor
9
+ class_option :verbose, :type => :boolean, :aliases => "-v"
10
+
11
+ desc "generate", "Generates VoiceXML from a given source file."
12
+ method_option :source, :aliases => "-s", :desc => "Specify the input file path. (Default: JSON)"
13
+ method_option :source_format, :desc => "Specify the source format."
14
+ method_option :destination, :aliases => "-d", :desc => "Specify the output file path."
15
+ method_option :destination_format, :desc => "Specify the destination format. (Default: VoiceXML 2.0)"
16
+ def generate
17
+ agnot = Gvg::Agnot.new
18
+ parser = Gvg::Parser.new
19
+ defaults = { source: File.join(resource_path(), 'hello.json'), destination: '/tmp/hello.vxml' }
20
+ notfound = File.join(resource_path(), '404.json')
21
+
22
+ source = options[:source] || defaults[:source]
23
+ source = File.file?(source) ? source : notfound
24
+
25
+ automaton = parser.parse(source)
26
+
27
+ agnot.start
28
+ states = automaton['states']
29
+ for state in states
30
+ agnot.send(state['type'], state['audio'])
31
+ end
32
+ agnot.stop
33
+ end
34
+ end
35
+
@@ -0,0 +1,17 @@
1
+ # A multi-lingual hello class to say hello in multiple languages.
2
+ class Gvg::Hello
3
+ # Say hi to the world!
4
+ #
5
+ # Example:
6
+ # >> Hola.hi("spanish")
7
+ #
8
+ # Arguments:
9
+ # language: (String)
10
+
11
+ def self.hi(language = "english")
12
+ translator = Translator.new(language)
13
+ translator.hi
14
+ end
15
+ end
16
+
17
+ require 'gvg/hello/translator'
@@ -0,0 +1,14 @@
1
+ class Gvg::Hello::Translator
2
+ def initialize(language)
3
+ @language = language
4
+ end
5
+
6
+ def hi
7
+ case @language
8
+ when "spanish"
9
+ "hola mundo"
10
+ else
11
+ "hello world"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ require 'json'
2
+
3
+ class Gvg::Parser
4
+ def parse(filename)
5
+ return JSON.parse(File.read(filename))
6
+ end
7
+ end
8
+
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "1",
3
+ "name": "Not Found",
4
+ "type": "error",
5
+ "description": "A state machine for 404 resource not found.",
6
+ "version": "1.0",
7
+ "states": [
8
+ {
9
+ "id": "1",
10
+ "sequence": "1",
11
+ "name": "Not Found",
12
+ "type": "say",
13
+ "description": "A state to say that the resource is not found.",
14
+ "audio": {
15
+ "source": "/media/audio?message=source-not-found&voice=default",
16
+ "text": "Requested resource not found."
17
+ }
18
+ }
19
+ ]
20
+ }
21
+
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "1",
3
+ "name": "Hello World",
4
+ "type": "hello",
5
+ "description": "An introductory hello world.",
6
+ "version": "1.0",
7
+ "states": [
8
+ {
9
+ "id": "1",
10
+ "sequence": "1",
11
+ "name": "Hello",
12
+ "type": "say",
13
+ "description": "A state to say hello world.",
14
+ "audio": {
15
+ "source": "/media/audio?message=hello-world&voice=default",
16
+ "text": "Hello World!"
17
+ }
18
+ }
19
+ ]
20
+ }
21
+
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gvg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Sailaja Nagireddy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A voicexml generator based on state machine.
14
+ email: sailaja.nagireddy@agnostic-foundation.org
15
+ executables:
16
+ - gvg
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/gvg
21
+ - lib/gvg.rb
22
+ - lib/gvg/agnot.rb
23
+ - lib/gvg/cli.rb
24
+ - lib/gvg/hello.rb
25
+ - lib/gvg/hello/translator.rb
26
+ - lib/gvg/parser.rb
27
+ - resources/404.json
28
+ - resources/hello.json
29
+ homepage: https://rubygems.org/gems/gvg
30
+ licenses:
31
+ - MPL-2.0
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ - resources
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.1.2
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Generic VoiceXML Generator
53
+ test_files: []