Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Aug 20, 2020
1 parent 906636a commit 26c9600
Show file tree
Hide file tree
Showing 17 changed files with 362 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
inherit_from:
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.4
Rails:
Enabled: true
Enabled: false
45 changes: 40 additions & 5 deletions lib/relaton_iso_bib/editorial_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class EditorialGroup
# @option workgroup [Integer] :number
#
# @param secretariat [String, NilClass]
def initialize(technical_committee:, **args)
def initialize(technical_committee:, **args) # rubocop:disable Metrics/CyclomaticComplexity
@technical_committee = technical_committee.map do |tc|
tc.is_a?(Hash) ? IsoSubgroup.new(tc) : tc
end
Expand All @@ -49,8 +49,9 @@ def initialize(technical_committee:, **args)
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength

# @param builder [Nokogiri::XML::Builder]
def to_xml(builder)
return unless technical_committee || subcommittee || workgroup || secretariat
def to_xml(builder) # rubocop:disable Metrics/CyclomaticComplexity
return unless technical_committee || subcommittee || workgroup ||
secretariat

builder.editorialgroup do
technical_committee.each do |tc|
Expand All @@ -69,12 +70,36 @@ def to_xml(builder)

# @return [Hash]
def to_hash
hash = { "technical_committee" => single_element_array(technical_committee) }
hash["subcommittee"] = single_element_array(subcommittee) if subcommittee&.any?
hash = {
"technical_committee" => single_element_array(technical_committee),
}
if subcommittee&.any?
hash["subcommittee"] = single_element_array(subcommittee)
end
hash["workgroup"] = single_element_array(workgroup) if workgroup&.any?
hash["secretariat"] = secretariat if secretariat
hash
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
pref = prefix.empty? ? prefix : prefix + "."
pref += "editorialgroup"
out = ""
technical_committee.each do |tc|
out += tc.to_asciibib "#{pref}.technical_committee",
technical_committee.size
end
subcommittee.each do |sc|
out += sc.to_asciibib "#{pref}.subcommittee", subcommittee.size
end
workgroup.each do |wg|
out += wg.to_asciibib "#{pref}.workgroup", workgroup.size
end
out += "#{pref}.secretariat:: #{secretariat}\n" if secretariat
out
end
end

# ISO subgroup.
Expand Down Expand Up @@ -111,5 +136,15 @@ def to_hash
hash["number"] = number if number
hash
end

# @param prefix [String]
# @param count [Integer] number of the elements
def to_asciibib(prefix, count = 1)
out = count > 1 ? "#{prefix}::\n" : ""
out += "#{prefix}.type:: #{type}\n" if type
out += "#{prefix}.number:: #{number}\n" if number
out += "#{prefix}.name:: #{name}\n"
out
end
end
end
15 changes: 14 additions & 1 deletion lib/relaton_iso_bib/ics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class Ics < Isoics::ICS
# @param subgroup [Integer, NilClass]
def initialize(code = nil, field: nil, group: nil, subgroup: nil)
unless code || field
raise ArgumentError, "wrong arguments (should be string or { fieldcode: [String] }"
raise ArgumentError,
"wrong arguments (should be string or { fieldcode: [String] }"
end

field, group, subgroup = code.split "." if code
Expand All @@ -28,5 +29,17 @@ def to_hash
hash["code"] = code if code
hash
end

# @param prefix [String]
# @param count [Integer] number of ICS
# @return [String]
def to_asciibib(prefix = "", count = 1)
pref = prefix.empty? ? prefix : prefix + "."
pref += "ics"
out = count > 1 ? "#{pref}::\n" : ""
out += "#{pref}.code:: #{code}\n"
out += "#{pref}.description:: #{description}\n"
out
end
end
end
20 changes: 13 additions & 7 deletions lib/relaton_iso_bib/iso_bibliographic_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require "nokogiri"
require "isoics"
require "relaton_bib"
# require "relaton_iso_bib/typed_title_string"
require "relaton_iso_bib/editorial_group"
require "relaton_iso_bib/xml_parser"
require "relaton_iso_bib/structured_identifier"
Expand Down Expand Up @@ -160,11 +159,11 @@ def initialize(**args)
end

# @return [String]
def to_xml(builder = nil, **opts, &block)
def to_xml(builder = nil, **opts)
if opts[:note]&.any?
opts.fetch(:note, []).each do |n|
@biblionote << RelatonBib::BiblioNote.new(
content: n[:text], type: n[:type], format: "text/plain",
content: n[:text], type: n[:type], format: "text/plain"
)
end
end
Expand All @@ -175,7 +174,7 @@ def to_xml(builder = nil, **opts, &block)
b.ext do
b.doctype doctype if doctype
b.docsubtype docsubtype if respond_to?(:docsubtype) && docsubtype
# GB renders gbcommittee elements istead of an editorialgroup element.
# GB renders gbcommittee elements istead of an editorialgroup
if respond_to? :committee
committee&.to_xml b
else
Expand All @@ -196,12 +195,19 @@ def to_xml(builder = nil, **opts, &block)
# @return [Hash]
def to_hash
hash = super
hash["editorialgroup"] = editorialgroup.to_hash if editorialgroup
hash["ics"] = single_element_array(ics) if ics&.any?
hash["stagename"] = stagename if stagename
hash
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix = "")
pref = prefix.empty? ? prefix : prefix + "."
out = super
out += "#{pref}stagename:: #{stagename}\n" if stagename
out
end

private

# @param doctype [String]
Expand All @@ -212,7 +218,7 @@ def check_doctype(doctype)
end
end

def makeid(id, attribute, _delim = "")
def makeid(id, attribute, _delim = "") # rubocop:disable Metrics/CyclomaticComplexity
return nil if attribute && !@id_attribute

id ||= @docidentifier.reject { |i| i&.type == "DOI" }[0]
Expand Down
33 changes: 27 additions & 6 deletions lib/relaton_iso_bib/structured_identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ def initialize(**args)
def remove_part
@part_number = nil
@subpart_number = nil
case @type
when "Chinese Standard" then @project_number = @project_number.sub(/\.\d+/, "")
else
@project_number = @project_number.sub(/-\d+/, "")
end
@project_number = case @type
when "Chinese Standard"
@project_number.sub(/\.\d+/, "")
else
@project_number = @project_number.sub(/-\d+/, "")
end
end

def remove_date
Expand All @@ -62,7 +63,9 @@ def to_xml(builder)
pn = builder.send "project-number", project_number
pn[:part] = part if part
pn[:subpart] = subpart if subpart
builder.send "tc-document-number", tc_document_number if tc_document_number
if tc_document_number
builder.send "tc-document-number", tc_document_number
end
end
xml[:type] = type if type
end
Expand All @@ -78,6 +81,24 @@ def to_hash
hash
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
pref = prefix.empty? ? prefix : prefix + "."
pref += "structured_identifier"
out = ""
if tc_document_number
out += "#{pref}.tc_document_number:: #{tc_document_number}\n"
end
if project_number
out += "#{pref}.project_number:: #{project_number}\n"
end
out += "#{pref}.part:: #{part}\n" if part
out += "#{pref}.subpart:: #{subpart}\n" if subpart
out += "#{pref}.type:: #{type}\n" if type
out
end

def presence?
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_iso_bib/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonIsoBib
VERSION = "1.2.0".freeze
VERSION = "1.3.0".freeze
end
2 changes: 1 addition & 1 deletion lib/relaton_iso_bib/xml_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def ttitle(title)
# @TODO Organization doesn't recreated
# @param ext [Nokogiri::XML::Element]
# @return [RelatonIsoBib::EditorialGroup]
def fetch_editorialgroup(ext)
def fetch_editorialgroup(ext) # rubocop:disable Metrics/CyclomaticComplexity
eg = ext&.at("./editorialgroup")
return unless eg

Expand Down
2 changes: 1 addition & 1 deletion relaton_iso_bib.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "simplecov"

spec.add_dependency "isoics", "~> 0.1.6"
spec.add_dependency "relaton-bib", "~> 1.2.0"
spec.add_dependency "relaton-bib", "~> 1.3.0"
end
Loading

0 comments on commit 26c9600

Please sign in to comment.