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

csvhuman - New Alternative (CSV) HXL Library / Gem in Ruby #5

Open
geraldb opened this issue Nov 6, 2018 · 0 comments
Open

csvhuman - New Alternative (CSV) HXL Library / Gem in Ruby #5

geraldb opened this issue Nov 6, 2018 · 0 comments

Comments

@geraldb
Copy link

geraldb commented Nov 6, 2018

Hello, first thanks for trying to build a ruby version for supporting HXL. I'm the author of the (new) csvreader library / gem and I added a new library / gem, that is, csvhuman, see https://github.com/csvreader/csvhuman, that lets you read tabular data in the CSV Humanitarian eXchange Language (HXL) format in ruby. Example:

pp CsvHuman.parse( <<TXT )      ## or use HXL.parse
  What,,,Who,Where,For whom,
  Record,Sector/Cluster,Subsector,Organisation,Country,Males,Females,Subregion
  ,#sector+en,#subsector,#org,#country,#sex+#targeted,#sex+#targeted,#adm1
  001,WASH,Subsector 1,Org 1,Country 1,100,100,Region 1
  002,Health,Subsector 2,Org 2,Country 2,,,Region 2
  003,Education,Subsector 3,Org 3,Country 2,250,300,Region 3
  004,WASH,Subsector 4,Org 1,Country 3,80,95,Region 4
TXT

More ways to use the reader:

csv = CsvHuman.new( recs )
csv.each do |rec|
  pp rec
end

pp csv.read


CsvHuman.parse( recs ).each do |rec|
  pp rec
end


pp CsvHuman.read( "./test.csv" )

CsvHuman.foreach( "./test.csv" ) do |rec|
  pp rec
end

#...

or use the HXL alias:

hxl = HXL.new( recs )
hxl.each do |rec|
  pp rec
end

pp hxl.read


HXL.parse( recs ).each do |rec|
  pp rec
end


pp HXL.read( "./test.csv" )

HXL.foreach( "./test.csv" ) do |rec|
  pp rec
end

#...

Cheers. Prost.

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

1 participant