Skip to content

parse source details#18

Open
HassanAkbar wants to merge 4 commits intomainfrom
source-details-parsing
Open

parse source details#18
HassanAkbar wants to merge 4 commits intomainfrom
source-details-parsing

Conversation

@HassanAkbar
Copy link
Member

fixes #1

@HassanAkbar HassanAkbar force-pushed the source-details-parsing branch from 6d6efff to a2532a0 Compare January 16, 2026 15:07
@HassanAkbar HassanAkbar marked this pull request as ready for review January 19, 2026 08:59
@HassanAkbar HassanAkbar requested a review from Copilot January 19, 2026 12:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces structured parsing for the <source details="..."> attribute by adding a Termium::SourceDetails value object and wiring it into Termium::Source.

Changes:

  • Add Termium::SourceDetails with casting/serialization and asterisk-delimited parsing.
  • Update Termium::Source#details to use SourceDetails and adjust #content formatting accordingly.
  • Add RSpec coverage for parsing, formatting, and XML round-tripping.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
spec/termium/source_spec.rb Adds tests for Termium::Source XML round-trip and #content formatting.
spec/termium/source_details_spec.rb Adds unit tests for Termium::SourceDetails casting/serialization behavior.
lib/termium/source_details.rb Introduces SourceDetails parser/type for the details attribute.
lib/termium/source.rb Switches details attribute to SourceDetails and updates matching logic.
lib/termium.rb Adds require_relative for source_details.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 38 to 42
if @organization
@author_name = presence(columns[0])
else
@standard = presence(columns[0])
end
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SourceDetails currently decides whether the first column is a standard vs author_name based on whether @organization (column 3) is present. Real fixture data includes entries like details="ISO/IEC JTC 1 * 2011" (see spec/fixtures/Characters.xml), where there is no 3rd column but the first column is not an ISO(-IEC)-* standard identifier. With the current logic this gets incorrectly stored in standard. Consider identifying standards by pattern (e.g., ISO-… / ISO-IEC-… with a document number), and otherwise treating the first column as a non-standard author/organization value.

Copilot uses AI. Check for mistakes.
end

def serialize(value)
value&.raw
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SourceDetails.serialize currently returns value&.raw, which will return nil if value is a plain String. That can drop data if callers set details to a raw string (or if the serializer passes a string through). Consider handling String inputs explicitly (e.g., returning the string as-is) in addition to SourceDetails instances.

Suggested change
value&.raw
return nil if value.nil?
return value.raw if value.is_a?(SourceDetails)
return value if value.is_a?(String)
value

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value parameter is expected to be a SourceDetails instance or nil, never a plain String. Strings are converted to SourceDetails via cast before serialize is called.


RSpec.describe Termium::SourceDetails do
describe ".cast" do
context "with ISO standard (no organization)" do
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context description says "with ISO standard (no organization)", but the input value is an ISO-IEC identifier ("ISO-IEC-2382-16 ..."). Updating the description to match the data will make the spec intent clearer.

Suggested change
context "with ISO standard (no organization)" do
context "with ISO/IEC standard (no organization)" do

Copilot uses AI. Check for mistakes.
@HassanAkbar HassanAkbar requested a review from ronaldtse January 19, 2026 14:11
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.

Parse <source> properly with its asterisks

1 participant