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

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

Direct Known Subclasses

Tropo::Ask::Choices

Instance Attribute Summary

Attributes inherited from RayoNode

#call_id, #client, #component_id, #connection, #original_component

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RayoNode

class_from_registration, import, #inspect, register, #source

Class Method Details

.new(options = {}) ⇒ Object

Parameters:

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

Options Hash (options):

  • :content_type (String)
  • :value (String)

    the choices available



221
222
223
224
225
226
227
228
229
230
231
# File 'lib/punchblock/component/input.rb', line 221

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]
    end
  end
end

Instance Method Details

#content_typeString

Returns the choice content type.

Returns:

  • (String)

    the choice content type



236
237
238
# File 'lib/punchblock/component/input.rb', line 236

def content_type
  read_attr 'content-type'
end

#content_type=(content_type) ⇒ Object

Parameters:

  • content_type (String)

    Defaults to the Voxeo Simple Grammar



243
244
245
# File 'lib/punchblock/component/input.rb', line 243

def content_type=(content_type)
  write_attr 'content-type', content_type || 'application/grammar+grxml'
end

#eql?(o, *fields) ⇒ true, false

Compare two Choices objects by content type, and value

Parameters:

  • o (Header)

    the Choices object to compare against

Returns:

  • (true, false)


264
265
266
# File 'lib/punchblock/component/input.rb', line 264

def eql?(o, *fields)
  super o, *(fields + [:content_type, :value])
end

#inspect_attributesObject

:nodoc:



268
269
270
# File 'lib/punchblock/component/input.rb', line 268

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

#valueString

Returns the choices available.

Returns:

  • (String)

    the choices available



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

def value
  content
end

#value=(value) ⇒ Object

Parameters:

  • value (String)

    the choices available



255
256
257
258
259
# File 'lib/punchblock/component/input.rb', line 255

def value=(value)
  Nokogiri::XML::Builder.with(self) do |xml|
    xml.cdata " #{value} "
  end
end