Class: AlexaModelMd

Inherits:
WikiMd
  • Object
show all
Defined in:
lib/alexa_modelmd.rb

Defined Under Namespace

Classes: Intent

Instance Method Summary collapse

Constructor Details

#initialize(wiki = nil, keywords = {}) ⇒ AlexaModelMd

Returns a new instance of AlexaModelMd.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/alexa_modelmd.rb', line 38

def initialize(wiki=nil, keywords={})
  
  wcis = keywords.delete :whatcanisay
  puts 'wcis: ' + wcis.inspect if @debug
  
  super(wiki, keywords)
  
  if wcis then
    
    found = self.find 'What can I say'

    if not found then
      
      s=<<EOF        
# What can I say

## WhatCanISay
      
* what can I say
* give me some examples

`
#rsc.alexamodelmd.sample_utterances '#{self.title}'
"Not yet enabled."
`

+ help whatcanisay
EOF

      self.create_section s
      
    end

  end
end

Instance Method Details

#endpointObject



91
# File 'lib/alexa_modelmd.rb', line 91

def endpoint()      @dxsx.dx.endpoint       end

#endpoint=(s) ⇒ Object



92
# File 'lib/alexa_modelmd.rb', line 92

def endpoint=(s)    @dxsx.dx.endpoint = s   end

#entriesObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/alexa_modelmd.rb', line 74

def entries()

  r = super()

  r.map do |entry|

    def entry.intents()
      puts 'entries | x: ' + x.inspect if @debug
      self.body().split(/(?=^## )/).map {|x| Intent.new(x, debug: @debug)}
    end

    entry

  end

end

#invocationObject



93
# File 'lib/alexa_modelmd.rb', line 93

def invocation()    @dxsx.dx.invocation     end

#invocation=(s) ⇒ Object



94
# File 'lib/alexa_modelmd.rb', line 94

def invocation=(s)  @dxsx.dx.invocation = s end

#save_rsfObject



96
97
98
99
100
101
102
# File 'lib/alexa_modelmd.rb', line 96

def save_rsf()
  if @dxsx.dx.respond_to? :rsf_file then
    FileX.write @dxsx.dx.rsf_file, to_rsf()
  else
    raise AMSummaryExceptiom, 'no rsf_file summary field found'
  end
end

#save_txtObject



104
105
106
107
108
109
110
# File 'lib/alexa_modelmd.rb', line 104

def save_txt()
  if @dxsx.dx.respond_to? :txt_file then
    FileX.write @dxsx.dx.txt_file, to_txt()
  else
    raise AMSummaryExceptiom, 'no txt_file summary field found'
  end
end

#to_mdObject

Transforms the document into an Alexa_modelmd formatted document



114
115
116
# File 'lib/alexa_modelmd.rb', line 114

def to_md
  Rexslt.new(md_xslt(), to_xml(), debug: @debug).to_s
end

#to_modelbObject Also known as: to_txt

This generates a plain text file representing the Alexa Model to be built using the alexa_modelbuilder gem



121
122
123
# File 'lib/alexa_modelmd.rb', line 121

def to_modelb
  Rexslt.new(modelbuilder_xslt(), to_xml()).to_s    
end

#to_rsfObject



127
128
129
# File 'lib/alexa_modelmd.rb', line 127

def to_rsf
  Rexslt.new(rsf_xslt(), to_xml(), debug: @debug).to_s
end

#to_xmlObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/alexa_modelmd.rb', line 131

def to_xml()

  a = RexleBuilder.build do |xml|

    xml.model do

      xml.summary do
        xml.title @dxsx.dx.title
        xml.invocation @dxsx.dx.invocation
        xml.endpoint @dxsx.dx.endpoint
      end

      xml.entries do 
        entries.each do |entry|

          xml.entry do
            xml.topic entry.heading.strip

            xml.intents do
              entry.intents.each do |intent|

                xml.intent do

                  xml.name intent.name

                  xml.utterances do
                    intent.utterances.each do |utterance|
                      xml.utterance utterance
                    end
                  end

                  xml.code do              
                    xml.cdata! intent.code
                  end
                end #/intent
              end
            end #/intents

            xml.tags do
              entry.tags.each do |tag|
                xml.tag tag
              end
            end
            
          end
        end 
      end #/entries

    end #/model
  end

  Rexle.new(a).xml pretty: true

end