Class: Punchblock::Component::Input::Grammar

Inherits:
RayoNode
  • Object
show all
Defined in:
lib/punchblock/component/input.rb

Constant Summary

Constants inherited from RayoNode

RayoNode::InvalidNodeError

Instance Attribute Summary

Attributes inherited from RayoNode

#client, #component_id, #connection, #domain, #original_component, #target_call_id, #target_mixer_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RayoNode

class_from_registration, #eql?, import, #inspect, register, #source

Class Method Details

.new(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :content_type (String)

    the document content type

  • :value (String)

    the grammar document

  • :url (String)

    the url from which to fetch the grammar



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/punchblock/component/input.rb', line 184

def self.new(options = {})
  super(:grammar).tap do |new_node|
    case options
    when Nokogiri::XML::Node
      new_node.inherit options
    when Hash
      new_node.content_type = options[:content_type]
      new_node.value = options[:value]
      new_node.url = options[:url]
    end
  end
end

Instance Method Details

#content_typeString

Returns the document content type.

Returns:

  • (String)

    the document content type



200
201
202
# File 'lib/punchblock/component/input.rb', line 200

def content_type
  read_attr 'content-type'
end

#content_type=(content_type) ⇒ Object

Parameters:

  • content_type (String)

    Defaults to GRXML



207
208
209
210
# File 'lib/punchblock/component/input.rb', line 207

def content_type=(content_type)
  return unless content_type
  write_attr 'content-type', content_type
end

#inspect_attributesObject

:nodoc:



250
251
252
# File 'lib/punchblock/component/input.rb', line 250

def inspect_attributes # :nodoc:
  [:content_type, :value, :url] + super
end

#urlString

Returns the URL from which the fetch the grammar.

Returns:

  • (String)

    the URL from which the fetch the grammar



239
240
241
# File 'lib/punchblock/component/input.rb', line 239

def url
  read_attr 'url'
end

#url=(other) ⇒ Object

Parameters:

  • other (String)

    the URL from which the fetch the grammar



246
247
248
# File 'lib/punchblock/component/input.rb', line 246

def url=(other)
  write_attr 'url', other
end

#valueString, RubySpeech::GRXML::Grammar

Returns the grammar document.

Returns:

  • (String, RubySpeech::GRXML::Grammar)

    the grammar document



214
215
216
217
218
219
220
221
# File 'lib/punchblock/component/input.rb', line 214

def value
  return nil unless content.present?
  if grxml?
    RubySpeech::GRXML.import content
  else
    content
  end
end

#value=(value) ⇒ Object

Parameters:

  • value (String, RubySpeech::GRXML::Grammar)

    the grammar document



225
226
227
228
229
230
231
232
233
234
# File 'lib/punchblock/component/input.rb', line 225

def value=(value)
  return unless value
  self.content_type = grxml_content_type unless self.content_type
  if grxml? && !value.is_a?(RubySpeech::GRXML::Element)
    value = RubySpeech::GRXML.import value
  end
  Nokogiri::XML::Builder.with(self) do |xml|
    xml.cdata " #{value} "
  end
end