lib/ruby_speech/grxml/item.rb in ruby_speech-0.4.0 vs lib/ruby_speech/grxml/item.rb in ruby_speech-0.5.0
- old
+ new
@@ -30,22 +30,11 @@
register :item
VALID_CHILD_TYPES = [Nokogiri::XML::Element, Nokogiri::XML::Text, OneOf, Item, String, Ruleref, Tag, Token].freeze
##
- # Create a new GRXML item element
#
- # @param [Hash] atts Key-value pairs of options mapping to setter methods
- #
- # @return [Item] an element for use in an GRXML document
- #
- def self.new(atts = {}, &block)
- super 'item', atts, &block
- end
-
- ##
- #
# The optional weight attribute
#
# @return [Float]
#
def weight
@@ -81,10 +70,11 @@
# http://www.w3.org/TR/speech-grammar/#S2.5
#
# @param [String] r
#
def repeat=(r)
+ r = "#{r.min}-#{r.max}" if r.is_a?(Range)
r = r.to_s
error = ArgumentError.new "A Item's repeat must be 0 or a positive integer"
raise error unless r.match(/[^0-9-]/) == nil and r.scan("-").size <= 1
@@ -127,9 +117,20 @@
super
end
def eql?(o)
super o, :weight, :repeat
+ end
+
+ def regexp_content # :nodoc:
+ return super unless repeat
+
+ if repeat.include?('-')
+ min, max = repeat.split '-'
+ "#{super}{#{min},#{max}}"
+ else
+ "#{super}{#{repeat}}"
+ end
end
end # Item
end # GRXML
end # RubySpeech