Skip to content

Commit

Permalink
[CS] Don't use #write_attr or #element_name from niceogiri monkey-pat…
Browse files Browse the repository at this point in the history
…ches
  • Loading branch information
benlangfeld committed Jul 13, 2012
1 parent d745cbf commit 858cc6f
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 39 deletions.
10 changes: 5 additions & 5 deletions lib/ruby_speech/generic_element.rb
Expand Up @@ -43,7 +43,7 @@ def class_from_registration(name)
def import(node)
node = Nokogiri::XML.parse(node, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS).root unless node.is_a?(Nokogiri::XML::Node)
return node.content if node.is_a?(Nokogiri::XML::Text)
klass = class_from_registration node.element_name
klass = class_from_registration node.node_name
if klass && klass != self
klass.import node
else
Expand Down Expand Up @@ -87,7 +87,7 @@ def version
end

def version=(other)
write_attr :version, other
self[:version] = other
end

##
Expand All @@ -101,7 +101,7 @@ def base_uri
# @param [String] uri the base URI to which relative URLs are resolved
#
def base_uri=(uri)
write_attr 'xml:base', uri
self['xml:base'] = uri
end

def to_doc
Expand Down Expand Up @@ -133,9 +133,9 @@ def children(type = nil, attributes = nil)
end.join(',') << ']' if attributes

if namespace_href
find "ns:#{expression}", :ns => namespace_href
xpath "ns:#{expression}", :ns => namespace_href
else
find expression
xpath expression
end
else
super()
Expand Down
8 changes: 4 additions & 4 deletions lib/ruby_speech/grxml/grammar.rb
Expand Up @@ -36,7 +36,7 @@ def mode
# @param [String] ia
#
def mode=(ia)
write_attr :mode, ia
self[:mode] = ia
end

##
Expand All @@ -53,7 +53,7 @@ def root
# @param [String] ia
#
def root=(ia)
write_attr :root, ia
self[:root] = ia
end

##
Expand All @@ -68,7 +68,7 @@ def tag_format
# @param [String] ia
#
def tag_format=(s)
write_attr :'tag-format', s
self['tag-format'] = s
end

##
Expand Down Expand Up @@ -104,7 +104,7 @@ def inline
# @return self
#
def inline!
find("//ns:ruleref", :ns => namespace_href).each do |ref|
xpath("//ns:ruleref", :ns => namespace_href).each do |ref|
rule = children(:rule, :id => ref[:uri].sub(/^#/, '')).first
ref.swap rule.nokogiri_children
end
Expand Down
6 changes: 3 additions & 3 deletions lib/ruby_speech/grxml/item.rb
Expand Up @@ -52,7 +52,7 @@ def weight
#
def weight=(w)
raise ArgumentError, "A Item's weight attribute must be a positive floating point number" unless w.to_s.match(/[^0-9\.]/) == nil and w.to_f >= 0
write_attr :weight, w
self[:weight] = w
end

##
Expand Down Expand Up @@ -99,7 +99,7 @@ def repeat=(r)
m < 0 || n < m
end
end
write_attr :repeat, r
self[:repeat] = r
end

##
Expand All @@ -117,7 +117,7 @@ def repeat_prob
#
def repeat_prob=(rp)
raise ArgumentError, "A Item's repeat probablity attribute must be a floating point number between 0.0 and 1.0" unless rp.to_s.match(/[^0-9\.]/) == nil and rp.to_f >= 0 and rp.to_f <= 1.0
write_attr :'repeat-prob', rp
self['repeat-prob'] = rp
end

def <<(arg)
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_speech/grxml/rule.rb
Expand Up @@ -36,7 +36,7 @@ def id
# @param [String] ia
#
def id=(ia)
write_attr :id, ia
self[:id] = ia
end

##
Expand All @@ -57,7 +57,7 @@ def scope
#
def scope=(sc)
raise ArgumentError, "A Rule's scope can only be 'public' or 'private'" unless %w{public private}.include?(sc.to_s)
write_attr :scope, sc
self[:scope] = sc
end

def <<(arg)
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_speech/grxml/ruleref.rb
Expand Up @@ -34,7 +34,7 @@ def uri
#
def uri=(u)
raise ArgumentError, "A Ruleref can only take uri or special" if special
write_attr :uri, u
self[:uri] = u
end

##
Expand All @@ -54,7 +54,7 @@ def special
def special=(sp)
raise ArgumentError, "A Ruleref can only take uri or special" if uri
raise ArgumentError, "The Ruleref#special method only takes :NULL, :VOID, and :GARBAGE" unless %w{NULL VOID GARBAGE}.include? sp.to_s
write_attr :special, sp
self[:special] = sp
end

def <<(*args)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_speech/ssml/audio.rb
Expand Up @@ -31,7 +31,7 @@ def src
# @param [String] the source. Must be a valid URI
#
def src=(s)
write_attr :src, s
self[:src] = s
end

def <<(arg)
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_speech/ssml/break.rb
Expand Up @@ -27,7 +27,7 @@ def strength
#
def strength=(s)
raise ArgumentError, "You must specify a valid strength (#{VALID_STRENGTHS.map(&:inspect).join ', '})" unless VALID_STRENGTHS.include? s
write_attr :strength, s
self[:strength] = s
end

##
Expand All @@ -46,7 +46,7 @@ def time
#
def time=(t)
raise ArgumentError, "You must specify a valid time (positive float value in seconds)" unless t.is_a?(Numeric) && t >= 0
write_attr :time, "#{t}s"
self[:time] = "#{t}s"
end

def <<(*args)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_speech/ssml/emphasis.rb
Expand Up @@ -28,7 +28,7 @@ def level
#
def level=(l)
raise ArgumentError, "You must specify a valid level (#{VALID_LEVELS.map(&:inspect).join ', '})" unless VALID_LEVELS.include? l
write_attr :level, l
self[:level] = l
end

def <<(arg)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_speech/ssml/mark.rb
Expand Up @@ -27,7 +27,7 @@ def name
# @param [String] the name token
#
def name=(other)
write_attr :name, other
self[:name] = other
end

def <<(*args)
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_speech/ssml/phoneme.rb
Expand Up @@ -40,7 +40,7 @@ def alphabet
# @param [String] other the phonemic/phonetic alphabet
#
def alphabet=(other)
write_attr :alphabet, other
self[:alphabet] = other
end

##
Expand All @@ -56,7 +56,7 @@ def ph
# @param [String] other the phoneme/phone string.
#
def ph=(other)
write_attr :ph, other
self[:ph] = other
end

def <<(arg)
Expand Down
12 changes: 6 additions & 6 deletions lib/ruby_speech/ssml/prosody.rb
Expand Up @@ -43,7 +43,7 @@ def pitch
def pitch=(p)
hz = p.is_a?(String) && p.include?('Hz') && p.to_f > 0
raise ArgumentError, "You must specify a valid pitch (\"[positive-number]Hz\", #{VALID_PITCHES.map(&:inspect).join ', '})" unless hz || VALID_PITCHES.include?(p)
write_attr :pitch, p
self[:pitch] = p
end

##
Expand All @@ -61,7 +61,7 @@ def contour
# @param [String] v
#
def contour=(v)
write_attr :contour, v
self[:contour] = v
end

##
Expand All @@ -87,7 +87,7 @@ def range
def range=(p)
hz = p.is_a?(String) && p.include?('Hz') && p.to_f > 0
raise ArgumentError, "You must specify a valid range (\"[positive-number]Hz\", #{VALID_PITCHES.map(&:inspect).join ', '})" unless hz || VALID_PITCHES.include?(p)
write_attr :range, p
self[:range] = p
end

##
Expand All @@ -112,7 +112,7 @@ def rate
#
def rate=(v)
raise ArgumentError, "You must specify a valid rate ([positive-number](multiplier), #{VALID_RATES.map(&:inspect).join ', '})" unless (v.is_a?(Numeric) && v >= 0) || VALID_RATES.include?(v)
write_attr :rate, v
self[:rate] = v
end

##
Expand All @@ -131,7 +131,7 @@ def duration
#
def duration=(t)
raise ArgumentError, "You must specify a valid duration (positive float value in seconds)" unless t.is_a?(Numeric) && t >= 0
write_attr :duration, "#{t}s"
self[:duration] = "#{t}s"
end

##
Expand All @@ -156,7 +156,7 @@ def volume
#
def volume=(v)
raise ArgumentError, "You must specify a valid volume ([positive-number](0.0 -> 100.0), #{VALID_VOLUMES.map(&:inspect).join ', '})" unless (v.is_a?(Numeric) && (0..100).include?(v)) || VALID_VOLUMES.include?(v)
write_attr :volume, v
self[:volume] = v
end

def <<(arg)
Expand Down
6 changes: 3 additions & 3 deletions lib/ruby_speech/ssml/say_as.rb
Expand Up @@ -42,7 +42,7 @@ def interpret_as
# @param [String] ia
#
def interpret_as=(ia)
write_attr :'interpret-as', ia
self['interpret-as'] = ia
end

##
Expand All @@ -61,7 +61,7 @@ def format
# @param [String] format
#
def format=(format)
write_attr :format, format
self[:format] = format
end

##
Expand All @@ -84,7 +84,7 @@ def detail
# @param [String] detail
#
def detail=(detail)
write_attr :detail, detail
self[:detail] = detail
end

def <<(arg)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_speech/ssml/sub.rb
Expand Up @@ -26,7 +26,7 @@ def alias
# @param [String] other the string to be spoken instead of the enclosed string
#
def alias=(other)
write_attr :alias, other
self[:alias] = other
end

def <<(arg)
Expand Down
8 changes: 4 additions & 4 deletions lib/ruby_speech/ssml/voice.rb
Expand Up @@ -29,7 +29,7 @@ def gender
#
def gender=(g)
raise ArgumentError, "You must specify a valid gender (#{VALID_GENDERS.map(&:inspect).join ', '})" unless VALID_GENDERS.include? g
write_attr :gender, g
self[:gender] = g
end

##
Expand All @@ -48,7 +48,7 @@ def age
#
def age=(i)
raise ArgumentError, "You must specify a valid age (non-negative integer)" unless i.is_a?(Integer) && i >= 0
write_attr :age, i
self[:age] = i
end

##
Expand All @@ -67,7 +67,7 @@ def variant
#
def variant=(i)
raise ArgumentError, "You must specify a valid variant (positive integer)" unless i.is_a?(Integer) && i > 0
write_attr :variant, i
self[:variant] = i
end

##
Expand All @@ -92,7 +92,7 @@ def name
def name=(n)
# TODO: Raise ArgumentError if names contain whitespace
n = n.join(' ') if n.is_a? Array
write_attr :name, n
self[:name] = n
end

def <<(arg)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_speech/xml/language.rb
Expand Up @@ -6,7 +6,7 @@ def language
end

def language=(l)
write_attr 'xml:lang', l
self['xml:lang'] = l
end
end # Language
end # XML
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby_speech/ssml/mark_spec.rb
Expand Up @@ -3,7 +3,7 @@
module RubySpeech
module SSML
describe Mark do
its(:element_name) { should == 'mark' }
its(:node_name) { should == 'mark' }

describe "setting options in initializers" do
subject { Mark.new :name => 'foo' }
Expand Down

0 comments on commit 858cc6f

Please sign in to comment.