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

Add Blocks support #61

Merged
merged 1 commit into from
Dec 16, 2014
Merged

Add Blocks support #61

merged 1 commit into from
Dec 16, 2014

Conversation

aderyabin
Copy link
Contributor

I suggest to handle values using blocks.
Less words - more examples:

element :title do  |title|
  "#{title}!!!"
end

attribute :id do |id|
  id.to_i
end

element :link, value: :foo do |link|
  link.downcase
end

@krasnoukhov
Copy link
Collaborator

Thanks! This looks pretty convenient. Merging ✨

krasnoukhov added a commit that referenced this pull request Dec 16, 2014
@krasnoukhov krasnoukhov merged commit a29294c into pauldix:master Dec 16, 2014
@krasnoukhov
Copy link
Collaborator

Also, @prodis you might be interested in this. Now your boolean use case implementation (see #58) can be much nicer:

require 'sax-machine'
require 'wannabe_bool'

class Fake
  include SAXMachine
  element :name
  element :main, &:to_b
  element :published, &:to_b
end

xml = '<fake><name>Prodis</name><main>true</main><published>false</published></fake>'

fake = Fake.parse(xml)
puts fake.main
puts fake.main.class

Output:

true
TrueClass

Do you mind giving it a try on master? Thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants