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

Migrate to lutaml-model #90

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
44a457d
WIP create some model elements
andrew2net May 31, 2024
fe3f055
WIP create some model elements
andrew2net Jun 11, 2024
5bf0ae8
WIP create some model elements
andrew2net Jun 12, 2024
f80f4ea
WIP create some model elements
andrew2net Jun 13, 2024
95d2694
WIP create some model elements
andrew2net Jun 14, 2024
e35ed82
WIP create some model elements
andrew2net Jun 16, 2024
6aa72ea
WIP create some model elements
andrew2net Jun 22, 2024
e03d0da
WIP create some model elements
andrew2net Jun 29, 2024
20cb40d
WIP
andrew2net Aug 3, 2024
77dd434
WIP
andrew2net Aug 23, 2024
596f8e4
WIP
andrew2net Sep 11, 2024
e1ed1e1
WIP
andrew2net Sep 29, 2024
f48e54f
WIP
andrew2net Nov 9, 2024
c415182
WIP
andrew2net Dec 8, 2024
b8cce92
Merge branch 'main' into shale-integration
andrew2net Dec 23, 2024
511cf82
WIP create Bibitem::Model classes
andrew2net Dec 31, 2024
1635994
WIP
andrew2net Jan 8, 2025
b2dcf03
WIP update old YAML parser, we need to convert old files to new format
andrew2net Jan 23, 2025
9b2008f
WIP
andrew2net Jan 24, 2025
3c62ca0
WIP fixing tests
andrew2net Jan 25, 2025
535ad13
Merge branch 'main' into shale-integration
andrew2net Jan 27, 2025
f0b1bcc
Merge branch 'main' into shale-integration
andrew2net Jan 28, 2025
482b74b
WIP update invalid date parsing test & Util's namespace
andrew2net Jan 28, 2025
3bde703
WIP remove custom models & old files
andrew2net Jan 29, 2025
e556fc0
WIP udate mappings & remove unused files
andrew2net Jan 30, 2025
77b1fe0
WIP add XML validation in tests
andrew2net Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/relaton/bib/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def initialize(**args) # rubocop:disable Metrics/CyclomaticComplexity
@formatted_address = args[:formatted_address] unless args[:city] && args[:country]
end

def ==(other) # rubocop:disable Metrics/AbcSize
Copy link
Contributor

Choose a reason for hiding this comment

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

Lutaml::Model supports equivalence checks of attributes

street == other.street && city == other.city && state == other.state &&
country == other.country && postcode == other.postcode &&
formatted_address == other.formatted_address
end

# @param doc [Nokogiri::XML::Document]
# def to_xml(doc) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# doc.address do
Expand Down
9 changes: 8 additions & 1 deletion lib/relaton/bib/affiliation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ class Affiliation
# @return [Relaton::Bib::LocalizedString, nil]
attr_accessor :name

attr_writer :description

# @return [Relaton::Bib::Organization]
attr_accessor :organization

# @param organization [Relaton::Bib::Organization, nil]
# @param name [Relaton::Bib::LocalizedString, nil]
# @param description [Array<Relaton::Bib::FormattedString>]
# @param description [Array<Relaton::Bib::LocalizedString>]
def initialize(organization: nil, name: nil, description: [])
@name = name
@organization = organization
@description = description
end

def ==(other)
Copy link
Contributor

Choose a reason for hiding this comment

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

As above.

name == other.name && organization == other.organization &&
description == other.description
end

# @param opts [Hash]
# @option opts [Nokogiri::XML::Builder] :builder XML builder
# @option opts [String] :lang language
Expand Down
8 changes: 4 additions & 4 deletions lib/relaton/bib/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Date
vote-started vote-ended announced stable-until].freeze

# @return [String]
attr_accessor :type, :text
attr_accessor :type, :text, :format

attr_writer :on, :from, :to

Expand Down Expand Up @@ -41,7 +41,7 @@ def initialize(**args)
# @return [String, Date, nil]
def from(part = nil) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
d = instance_variable_get "@#{__callee__}".to_sym
return d unless part && d
return date_format(d) unless part && d

# date = parse_date(d)
# return date if part == :date
Expand Down Expand Up @@ -102,14 +102,14 @@ def to_asciibib(prefix = "", count = 1)
# @param date [String]
# @param format [Symbol, nil] :full (yyyy-mm-dd), :short (yyyy-mm) or nil
# @return [String]
def date_format(date, format = nil)
def date_format(date)
tmplt = case format
when :short then "%Y-%m"
when :full then "%Y-%m-%d"
else return date
end
d = parse_date(date)
d.is_a?(Date) ? d.strftime(tmplt) : d
d.respond_to?(:strftime) ? d.strftime(tmplt) : d
end

# @param date [String]
Expand Down
1 change: 0 additions & 1 deletion lib/relaton/bib/docidentifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module Relaton
module Bib
# Document identifier.
class Docidentifier < DocidentifierType

#
# Add docidentifier xml element
#
Expand Down
4 changes: 4 additions & 0 deletions lib/relaton/bib/docidentifier_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def initialize(**args)
@primary = args[:primary]
end

def content=(value)
@content = value.strip
end

# in docid manipulations, assume ISO as the default: id-part:year
def remove_part
case @type
Expand Down
30 changes: 15 additions & 15 deletions lib/relaton/bib/document_type.rb → lib/relaton/bib/doctype.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module Relaton
module Bib
class DocumentType
attr_reader :type, :abbreviation
class Doctype
attr_accessor :content, :abbreviation

#
# Initialize a DocumentType.
#
# @param [String] type document type
# @param [String] content document type
# @param [String, nil] abbreviation type abbreviation
#
def initialize(type:, abbreviation: nil)
@type = type
def initialize(content: nil, abbreviation: nil)
@content = content
@abbreviation = abbreviation
end

Expand All @@ -19,21 +19,21 @@ def initialize(type:, abbreviation: nil)
#
# @param [Nokogiri::XML::Builder] builder XML builder
#
def to_xml(builder)
xml = builder.doctype @type
xml[:abbreviation] = @abbreviation if @abbreviation
end
# def to_xml(builder)
# xml = builder.doctype @content
# xml[:abbreviation] = @abbreviation if @abbreviation
# end

#
# Hash representation of the document type.
#
# @return [Hash]
#
def to_hash
hash = { "type" => @type }
hash["abbreviation"] = @abbreviation if @abbreviation
hash
end
# def to_hash
# hash = { "type" => @content }
# hash["abbreviation"] = @abbreviation if @abbreviation
# hash
# end

#
# Asciibib representation of the document type.
Expand All @@ -45,7 +45,7 @@ def to_hash
def to_asciibib(prefix = "")
pref = prefix.empty? ? prefix : "#{prefix}."
pref += "doctype."
out = "#{pref}type:: #{@type}\n"
out = "#{pref}content:: #{@content}\n"
out += "#{pref}abbreviation:: #{@abbreviation}\n" if @abbreviation
out
end
Expand Down
22 changes: 11 additions & 11 deletions lib/relaton/bib/editorial_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ module Bib
class EditorialGroup
# include Relaton

# @return [Array<Relaton::Bib::TechnicalCommittee>]
# @return [Array<Relaton::Bib::WorkGroup>]
attr_accessor :technical_committee

# @param technical_committee [Array<Relaton::Bib::TechnicalCommittee>]
def initialize(technical_committee)
# @param technical_committee [Array<Relaton::Bib::WorkGroup>]
def initialize(technical_committee = [])
@technical_committee = technical_committee
end

# @param builder [Nokogigi::XML::Builder]
def to_xml(builder)
builder.editorialgroup do |b|
technical_committee.each { |tc| tc.to_xml b }
end
end
# def to_xml(builder)
# builder.editorialgroup do |b|
# technical_committee.each { |tc| tc.to_xml b }
# end
# end

# @return [Hash]
def to_hash
single_element_array technical_committee
end
# def to_hash
# single_element_array technical_committee
# end

# @param prefix [String]
# @return [String]
Expand Down
13 changes: 11 additions & 2 deletions lib/relaton/bib/ext.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
require_relative "doctype"
require_relative "editorial_group"
require_relative "ics"
require_relative "structured_identifier"

module Relaton
module Bib
class Ext
attr_reader :editorialgroup, :ics, :structuredidentifier
attr_accessor :doctype, :subdoctype, :flavor, :editorialgroup, :ics

attr_reader :structuredidentifier

# @param doctype [Relaton::Bib::DocumentType]
# @param subdoctype [String]
# @param flavor [String]
# @param editorialgroup [Relaton::Bib::EditorialGroup, nil]
# @param ics [Array<Relaton::Bib::ICS>]
# @param structuredidentifier [Relaton::Bib::StructuredIdentifierCollection]
def initialize(**args)
@editorialgroup = args[:editorialgroup] || []
@doctype = args[:doctype]
@subdoctype = args[:subdoctype]
@flavor = args[:flavor]
@editorialgroup = args[:editorialgroup]
@ics = args[:ics] || []
@structuredidentifier = args[:structuredidentifier] || StructuredIdentifierCollection.new
end
Expand Down
18 changes: 12 additions & 6 deletions lib/relaton/bib/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require_relative "phone"
require_relative "uri"
require_relative "affiliation"
require_relative "document_type"
require_relative "image"
require_relative "forename"
require_relative "full_name"
Expand Down Expand Up @@ -132,8 +131,6 @@ class Item
# @param keyword [Array<String>]
# @param validity [Relaton::Bib:Validity, nil]
# @param depiction [Relaton::Bib::Depiction, nil]
# @param doctype [Relaton::Bib::DocumentType]
# @param subdoctype [String]
# @param size [Relaton::Bib::Size, nil]
# @param ext [Relaton::Bib::Ext, nil]
def initialize(**args)
Expand All @@ -154,9 +151,18 @@ def relation=(relation)
@relation = relation.is_a?(RelationCollection) ? relation : RelationCollection.new(relation)
end

# def title_to_xml(mode, doc, builder)
# doc
# end
#
# <Description>
#
# @param [Symbol, nil] format format of date output (:short, :full)
#
# @return [Realton::Bib::Item]
#
def date_format(format = nil)
item = deep_clone
item.date.each { |d| d.format = format }
item
end

#
# Fetch schema version
Expand Down
4 changes: 2 additions & 2 deletions lib/relaton/bib/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def to_asciibib(prefix = "", count = 1)
# end
# end

# @return [Array<Relaton::Bib::Organization::Name>]
# @return [Array<Relaton::Bib::TypedLocalizedString>]
attr_accessor :name

# @return [Relaton::Bib::LocalizedString, nil]
Expand Down Expand Up @@ -123,7 +123,7 @@ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize,Metric
out += sd.to_asciibib "#{pref}.subdivision"
end
identifier.each { |n| out += n.to_asciibib pref, identifier.size }
out += super pref
# out += super pref
out += logo.to_asciibib "#{pref}.logo" if logo
out
end
Expand Down
12 changes: 6 additions & 6 deletions lib/relaton/bib/technical_committee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ def initialize(workgroup)
end

# @param builder [Nokogiri::XML::Builder]
def to_xml(builder)
builder.send(:"technical-committee") { |b| workgroup.to_xml b }
end
# def to_xml(builder)
# builder.send(:"technical-committee") { |b| workgroup.to_xml b }
# end

# @return [Hash]
def to_hash
workgroup.to_hash
end
# def to_hash
# workgroup.to_hash
# end

# @param prefix [String]
# @param count [Integer] number of technical committees
Expand Down
44 changes: 22 additions & 22 deletions lib/relaton/bib/workgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,53 @@ module Relaton
module Bib
class WorkGroup
# @return [String]
attr_reader :name
attr_accessor :content

# @return [Integer, nil]
attr_reader :number
attr_accessor :number

# @return [String, nil]
attr_reader :identifier, :prefix, :type
attr_accessor :identifier, :prefix, :type

# @param name [String]
# @param content [String]
# @param identifier [String, nil]
# @param prefix [String, nil]
# @param number [Integer, nil]
# @param type [String, nil]
def initialize(name:, identifier: nil, prefix: nil, number: nil, type: nil)
def initialize(content: nil, identifier: nil, prefix: nil, number: nil, type: nil)
@identifier = identifier
@prefix = prefix
@name = name
@content = content
@number = number
@type = type
end

# @param builder [Nokogiri::XML::Builder]
def to_xml(builder) # rubocop:disable Metrics/AbcSize
builder.text name
builder.parent[:number] = number if number
builder.parent[:type] = type if type
builder.parent[:identifier] = identifier if identifier
builder.parent[:prefix] = prefix if prefix
end
# def to_xml(builder) # rubocop:disable Metrics/AbcSize
# builder.text name
# builder.parent[:number] = number if number
# builder.parent[:type] = type if type
# builder.parent[:identifier] = identifier if identifier
# builder.parent[:prefix] = prefix if prefix
# end

# @return [Hash]
def to_hash
hash = { "name" => name }
hash["number"] = number if number
hash["type"] = type if type
hash["identifier"] = identifier if identifier
hash["prefix"] = prefix if prefix
hash
end
# def to_hash
# hash = { "name" => name }
# hash["number"] = number if number
# hash["type"] = type if type
# hash["identifier"] = identifier if identifier
# hash["prefix"] = prefix if prefix
# hash
# end

# @param prfx [String]
# @param count [Integer]
# @return [String]
def to_asciibib(prfx = "", count = 1) # rubocop:disable Metrics/CyclomaticComplexity
pref = prfx.empty? ? prfx : "#{prfx}."
out = count > 1 ? "#{pref}::\n" : ""
out += "#{pref}name:: #{name}\n"
out += "#{pref}content:: #{content}\n"
out += "#{pref}number:: #{number}\n" if number
out += "#{pref}type:: #{type}\n" if type
out += "#{pref}identifier:: #{identifier}\n" if identifier
Expand Down
Loading
Loading