|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Build, Test, and Development Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +# Install dependencies |
| 9 | +bundle install |
| 10 | + |
| 11 | +# Run tests |
| 12 | +bundle exec rspec |
| 13 | + |
| 14 | +# Run a single test file |
| 15 | +bundle exec rspec spec/tbx/document_spec.rb |
| 16 | + |
| 17 | +# Run linting |
| 18 | +bundle exec rubocop |
| 19 | + |
| 20 | +# Run both (default task) |
| 21 | +bundle exec rake |
| 22 | +``` |
| 23 | + |
| 24 | +## Architecture |
| 25 | + |
| 26 | +This is a Ruby gem for parsing and serializing TBX (Termbase Exchange) documents per ISO 30042:2019. It uses `lutaml-model` for XML serialization/deserialization. |
| 27 | + |
| 28 | +### Namespace Structure |
| 29 | + |
| 30 | +``` |
| 31 | +Tbx |
| 32 | +├── Document # Root element (<tbx>) |
| 33 | +├── TbxHeader # <tbxHeader> |
| 34 | +├── FileDesc # <fileDesc> |
| 35 | +├── PublicationStmt # <publicationStmt> |
| 36 | +├── TitleStmt # <titleStmt> |
| 37 | +├── SourceDesc # <sourceDesc> |
| 38 | +├── EncodingDesc # <encodingDesc> |
| 39 | +├── RevisionDesc # <revisionDesc> |
| 40 | +├── Change # <change> |
| 41 | +├── TextElement # <text> |
| 42 | +├── Body # <body> |
| 43 | +├── Back # <back> |
| 44 | +├── ConceptEntry # <conceptEntry> |
| 45 | +├── LangSec # <langSec> |
| 46 | +├── TermSec # <termSec> |
| 47 | +├── Term # <term> |
| 48 | +├── TermNote # <termNote> |
| 49 | +├── TermNoteGrp # <termNoteGrp> |
| 50 | +├── Descrip # <descrip> |
| 51 | +├── DescripGrp # <descripGrp> |
| 52 | +├── DescripNote # <descripNote> |
| 53 | +├── Admin # <admin> |
| 54 | +├── AdminGrp # <adminGrp> |
| 55 | +├── AdminNote # <adminNote> |
| 56 | +├── Note # <note> |
| 57 | +├── P # <p> |
| 58 | +├── Ref # <ref> |
| 59 | +├── Xref # <xref> |
| 60 | +├── Transac # <transac> |
| 61 | +├── TransacGrp # <transacGrp> |
| 62 | +├── TransacNote # <transacNote> |
| 63 | +├── DateElement # <date> |
| 64 | +├── RefObjectSec # <refObjectSec> |
| 65 | +├── RefObject # <refObject> |
| 66 | +├── ItemSet # <itemSet> |
| 67 | +├── ItemGrp # <itemGrp> |
| 68 | +├── Item # <item> |
| 69 | +├── Hi # <hi> |
| 70 | +├── Foreign # <foreign> |
| 71 | +├── Ec # <ec> |
| 72 | +├── Sc # <sc> |
| 73 | +├── Ph # <ph> |
| 74 | +├── Title # <title> |
| 75 | +├── Namespaces # XML namespace definitions |
| 76 | +└── Ruby # Gem namespace (Tbx::Ruby::VERSION) |
| 77 | +``` |
| 78 | + |
| 79 | +### Key Implementation Patterns |
| 80 | + |
| 81 | +**Element Classes** (in `lib/tbx/`): |
| 82 | +- Inherit from `Lutaml::Model::Serializable` |
| 83 | +- Define attributes and XML mapping in `xml do ... end` block |
| 84 | +- Use `map_element` to map child elements, `map_content` for text content |
| 85 | +- Use `mixed_content` for elements that contain both text and child elements |
| 86 | +- Use `w3c_attributes` for `xml:lang` and other W3C attributes |
| 87 | + |
| 88 | +**Example element structure:** |
| 89 | +```ruby |
| 90 | +module Tbx |
| 91 | + class ConceptEntry < Lutaml::Model::Serializable |
| 92 | + attribute :id, :string |
| 93 | + attribute :lang_sec, ::Tbx::LangSec, collection: true |
| 94 | + |
| 95 | + xml do |
| 96 | + root "conceptEntry" |
| 97 | + mixed_content |
| 98 | + namespace ::Tbx::Namespaces::TbxNamespace |
| 99 | + |
| 100 | + map_attribute "id", to: :id |
| 101 | + map_element "langSec", to: :lang_sec |
| 102 | + end |
| 103 | + end |
| 104 | +end |
| 105 | +``` |
| 106 | + |
| 107 | +**Autoload Pattern**: Elements are autoloaded via `lib/tbx.rb`. When adding new elements, add autoloads in alphabetical order. |
| 108 | + |
| 109 | +### XML Namespace |
| 110 | + |
| 111 | +The TBX namespace is `urn:iso:std:iso:30042:ed-2` defined in `Tbx::Namespaces::TbxNamespace`. |
| 112 | + |
| 113 | +### TBX Styles |
| 114 | + |
| 115 | +- **DCA** (Data Category Archive): Uses standard element names like `<transac type="transactionType">`, `<descrip type="definition">` |
| 116 | +- **DCT** (Data Category Tagging): Uses module-namespaced elements like `<basic:transactionType>`, `<basic:definition>` |
| 117 | + |
| 118 | +Currently DCA style is fully supported. DCT support will be added. |
| 119 | + |
| 120 | +### Reference Data |
| 121 | + |
| 122 | +- RNG/XSD schemas: `reference-docs/schemas/` |
| 123 | +- TBX-Basic dialect examples: `reference-docs/schemas/TBX-Basic_dialect_v1/` |
| 124 | +- Test fixtures: `spec/fixtures/TBX_test_files/` (from https://github.com/LTAC-Global/TBX_test_files) |
0 commit comments