Skip to content

Instantly share code, notes, and snippets.

@zdman135
Last active August 29, 2015 14:20
Show Gist options
  • Save zdman135/5db58025f540368e0498 to your computer and use it in GitHub Desktop.
Save zdman135/5db58025f540368e0498 to your computer and use it in GitHub Desktop.
json data
[
{
"keyword": "Feature",
"name": "another feature",
"line": 2,
"description": "",
"tags": [
{
"name": "@test",
"line": 1
}
],
"id": "another-feature",
"uri": "features/dashboard/foo.feature",
"elements": [
{
"keyword": "Scenario",
"name": "another test scenario",
"line": 4,
"description": "",
"id": "another-feature;another-test-scenario",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I have something",
"line": 5,
"match": {
"location": "features/dashboard/foo.feature:5"
},
"result": {
"status": "undefined",
"duration": 2066999
}
},
{
"keyword": "When ",
"name": "I do something",
"line": 6,
"match": {
"location": "features/dashboard/foo.feature:6"
},
"result": {
"status": "undefined",
"duration": 456000
}
},
{
"keyword": "Then ",
"name": "I see something is done",
"line": 7,
"match": {
"location": "features/dashboard/foo.feature:7"
},
"result": {
"status": "undefined",
"duration": 416000
}
}
]
}
]
},
{
"keyword": "Feature",
"name": "test feature name",
"line": 2,
"description": "\nIn order to test\nas a tester\nI want to test",
"tags": [
{
"name": "@test",
"line": 1
}
],
"id": "test-feature-name",
"uri": "features/dashboard/test.feature",
"elements": [
{
"keyword": "Scenario",
"name": "test scenario",
"line": 8,
"description": "",
"id": "test-feature-name;test-scenario",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I have something",
"line": 9,
"match": {
"location": "features/dashboard/test.feature:9"
},
"result": {
"status": "undefined",
"duration": 429000
}
},
{
"keyword": "When ",
"name": "it is done",
"line": 10,
"match": {
"location": "features/dashboard/test.feature:10"
},
"result": {
"status": "undefined",
"duration": 455000
}
},
{
"keyword": "Then ",
"name": "I see something",
"line": 11,
"match": {
"location": "features/dashboard/test.feature:11"
},
"result": {
"status": "undefined",
"duration": 447000
}
}
]
}
]
}
]
@zdman135
Copy link
Author

I need a hash that looks like this:
{
cuke_name => "test feature name", #arr[0]["name"]
cuke_description => "\nIn order to test\nas a tester\nI want to test",
}

@IceDragon200
Copy link

result = data.map do |feature|
  { cuke_name: feature['name'], cuke_description: feature['description'] }
end
result 

This will give you an Array, of Hashes with cuke_name, cuke_desription keys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment