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 cast modifier for boolean values #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lucidstack
Copy link

Hi there! Thank you for making sweet_xml, it works amazingly well. 😀

While parsing an XML with some boolean values, I realised that boolean values are actually standardised in the XML Schema specification, with values true and false (and non-canonically 0 and 1).

I think having a b modifier for the ~x sigil would be a nice addition! I have included a test case for casting with b, and checking for the sigil with b, bl, and lb

Please let me know what you think, and if I need to make any additional changes!

Thanks again! 👋

@kagux
Copy link

kagux commented Nov 21, 2016

Hi,

This would be a very helpful feature to have. Any reason this wasn't merged?

@lucidstack
Copy link
Author

@awetzel any update on this?

@aeden
Copy link
Collaborator

aeden commented Dec 29, 2017

@lucidstack If you can rebase and fix the conflicts, I can handle the merge.

@doughsay
Copy link

Hey there, I need this feature for a project I'm trying to use sweet_xml for. Can we get the conflicts fixed and get this merged?

@chulkilee
Copy link

chulkilee commented Jun 8, 2018

BTW you can do this using transform_by/2

 ~x"./first/text()" |> transform_to_boolean()

defp transform_to_boolean(arg) do
  transform_by(arg, fn
    'false' -> false
    'true' -> true
    "" -> nil
  end)
end

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.

5 participants