Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't convert Saxerator::Builder::StringElement to Array #62

Open
Tracked by #66
voke opened this issue Nov 8, 2017 · 4 comments
Open
Tracked by #66

can't convert Saxerator::Builder::StringElement to Array #62

voke opened this issue Nov 8, 2017 · 4 comments

Comments

@voke
Copy link

voke commented Nov 8, 2017

According to the README:

You can treat objects consistently as arrays using Ruby's built-in array conversion method in the form Array(element_or_array)

Snippet:

require 'saxerator'

p RUBY_VERSION # => "2.3.1"
p Saxerator::VERSION # => "0.9.8"

xml = <<-XML
<root>
  <product>
    <items>
      <item>foo</item>
      <item>bar</item>
    </items>
  </product>
  <product>
    <items>
      <item>lonely</item>
    </items>
  </product>
</root>
XML

parser = Saxerator.parser(xml)

parser.for_tag("product").each do |node|
  p Array(node['items']['item'])
end

gives

`Array': can't convert Saxerator::Builder::StringElement to Array (Saxerator::Builder::StringElement#to_a gives Saxerator::Builder::ArrayElement) (TypeError)
@fanantoxa
Copy link
Collaborator

@soulcutter I've checked is really a bug. Could you check when find a time please?

@voke
Copy link
Author

voke commented Nov 9, 2017

I think the problem is this commit which changed the behaviour.

# string_element.rb
def to_a
  ArrayElement.new(self, name)
end

should probably be

def to_a
  ArrayElement.new([self], name)
end

@fanantoxa
Copy link
Collaborator

@voke Already tested it and it's doesn't work. I thing Array() expect and exactly Array object.

@soulcutter
Copy link
Owner

I think this behavior changed when we stopped extending core ruby classes, using delegation instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants