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, 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



239
240
241
242
243
244
245
246
247
248
249
# File 'lib/punchblock/component/input.rb', line 239

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



254
255
256
# File 'lib/punchblock/component/input.rb', line 254

def content_type
  read_attr 'content-type'
end

#content_type=(content_type) ⇒ Object

Parameters:

  • content_type (String)

    Defaults to GRXML



261
262
263
# File 'lib/punchblock/component/input.rb', line 261

def content_type=(content_type)
  write_attr 'content-type', content_type || grxml_content_type
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)


290
291
292
# File 'lib/punchblock/component/input.rb', line 290

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

#inspect_attributesObject

:nodoc:



294
295
296
# File 'lib/punchblock/component/input.rb', line 294

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

#valueString

Returns the choices available.

Returns:

  • (String)

    the choices available



267
268
269
270
271
272
273
# File 'lib/punchblock/component/input.rb', line 267

def value
  if grxml?
    RubySpeech::GRXML.import content
  else
    content
  end
end

#value=(value) ⇒ Object

Parameters:

  • value (String)

    the choices available



277
278
279
280
281
282
283
284
285
# File 'lib/punchblock/component/input.rb', line 277

def value=(value)
  return unless value
  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