Skip to content

Commit

Permalink
apply formulas to both xml tags and attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiii committed Jul 4, 2011
1 parent 724ca82 commit 6652d96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/nori/xml_utility_node.rb
Expand Up @@ -88,11 +88,15 @@ def initialize(name, normalized_attributes = {})

def prefixed_attributes
attributes.inject({}) do |memo, (key, value)|
memo["@#{key}"] = value
memo[prefixed_attribute_name("@#{key}")] = value
memo
end
end

def prefixed_attribute_name(attribute)
Nori.convert_tags? ? Nori.convert_tag(attribute) : attribute
end

def add_node(node)
@text = true if node.is_a? String
@children << node
Expand Down
4 changes: 2 additions & 2 deletions spec/nori/nori_spec.rb
Expand Up @@ -296,8 +296,8 @@
end

it "transforms the tags to snakecase Symbols" do
xml = '<userResponse><accountStatus>active</accountStatus></userResponse>'
parse(xml).should == { :user_response => { :account_status => "active" } }
xml = '<userResponse id="1"><accountStatus>active</accountStatus></userResponse>'
parse(xml).should == { :user_response => { :@id => "1", :account_status => "active" } }
end
end

Expand Down

0 comments on commit 6652d96

Please sign in to comment.