Created
January 20, 2011 22:49
-
-
Save Yardboy/788860 to your computer and use it in GitHub Desktop.
HappyMapper class definition puzzler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<manifest> | |
<organization> | |
<item identifier="ITEM-6137565f-18fe-481f-b6ce-a290a354c862" isvisible="true"> | |
<title>Math</title> | |
<item identifier="ITEM-5781bd41-7acd-4373-8ccd-37bd074c2461"> | |
<title>Grade 07</title> | |
<item identifier="ITEM-d7035880-88a5-4501-9865-f6265ba8022c" identifierref="i-179211"> | |
<title>qti_200535.xml</title> | |
</item> | |
<item identifier="ITEM-b13ebebd-f942-4ee8-a342-e8c3913c9063" identifierref="i-194469"> | |
<title>qti_200577.xml</title> | |
</item> | |
</item> | |
<item identifier="ITEM-39ade5bb-b9a4-48f6-ba48-8c14177c1f65"> | |
<title>Grades 09-12</title> | |
<item identifier="ITEM-13bca2de-134c-4ea5-a69c-50678eba65d5" identifierref="i-180165"> | |
<title>qti_200600.xml</title> | |
</item> | |
<item identifier="ITEM-4b86431d-be1f-4e17-b718-e2e5c2235e67" identifierref="i-179198"> | |
<title>qti_200687.xml</title> | |
</item> | |
<item identifier="ITEM-4145e484-85bb-4885-8f68-3b8dd3532350" identifierref="i-181841"> | |
<title>qti_200688.xml</title> | |
</item> | |
<item identifier="ITEM-30255959-d5f9-45ec-affa-83dc3bf0eb12" identifierref="i-189098"> | |
<title>qti_201128.xml</title> | |
</item> | |
</item> | |
<item identifier="ITEM-84a2b794-104d-4357-af4d-c330b1ce8f16"> | |
<title>Grade 08</title> | |
<item identifier="ITEM-f95d6101-8d87-431d-8da0-8140a05cda98" identifierref="i-179490"> | |
<title>qti_201790.xml</title> | |
</item> | |
<item identifier="ITEM-4864e3f7-1d5b-497f-b026-b6a0c7c51ea6" identifierref="i-193275"> | |
<title>qti_201854.xml</title> | |
</item> | |
</item> | |
</item> | |
</organization> | |
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I've noodled around with these four definitions: | |
class Item | |
include HappyMapper | |
tag 'item' | |
element :title, String, :tag => 'title' | |
end | |
class Grade | |
include HappyMapper | |
tag 'item' | |
element :title, String, :tag => 'title' | |
has_many :items, Item | |
end | |
class Subject | |
include HappyMapper | |
tag 'item' | |
element :title, String, :tag => 'title' | |
has_many :grades, Grade | |
end | |
class Manifest | |
include HappyMapper | |
tag 'manifest' | |
has_one :subject, Subject, :deep => true | |
end | |
# This gets me manifest.subject, but manifest.grades includes the | |
# 2nd and 3rd levels, and manifest.grades[n].items is []. | |
# Any help appreciated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is an Educational Testing Service XML format based on the QTI specification. | |
As you can see below, this XML spec nests <item> tags that essentially mean different | |
things. In this case, the first <item> tag level below organization is what I would | |
term "subject", the second level is what I would term "grade", and the third level is | |
the thing I actually reference as an "item". I need to capture the subject and grade | |
information, but when I process "items", I only want those ones at the third level. | |
Ideally, I'd like to be able to reference: | |
manifest.subject //Math | |
manifest.subject.grades | |
manifest.subject.grades[n].items | |
But I can't figure out how to write the class definitions for HappyMapper use, | |
because everything's an <item>. The different <item> tags have attributes that | |
appear to reliably identify the pieces, but not sure how to use that to my | |
advantage. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment