Class: Metanorma::Release::Publication
- Inherits:
-
Object
- Object
- Metanorma::Release::Publication
- Defined in:
- lib/metanorma/release/publication.rb
Constant Summary collapse
- METADATA_VERSION =
1- DRAFT_STAGES =
%w[ 20 30 40 50 working-draft committee-draft draft-standard final-draft ].freeze
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#doctype ⇒ Object
readonly
Returns the value of attribute doctype.
-
#edition ⇒ Object
readonly
Returns the value of attribute edition.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#revdate ⇒ Object
readonly
Returns the value of attribute revdate.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#stage ⇒ Object
readonly
Returns the value of attribute stage.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
- .from_json(json_string) ⇒ Object
- .from_metadata_hash(data) ⇒ Object
- .from_release_body(body) ⇒ Object
Instance Method Summary collapse
- #base_dir ⇒ Object
- #content_hash(from_directory: nil) ⇒ Object
- #draft? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #file?(format) ⇒ Boolean
- #formats ⇒ Object
- #hash ⇒ Object
-
#initialize(identifier:, slug:, title:, edition:, stage:, doctype:, revdate:, files:, channels:, source: nil, metadata_formats: nil) ⇒ Publication
constructor
A new instance of Publication.
- #to_h ⇒ Object
- #to_json(*_args) ⇒ Object
- #to_release_body ⇒ Object
- #with_channels(new_channels) ⇒ Object
- #with_files_and_source(new_files, release, repo) ⇒ Object
Constructor Details
#initialize(identifier:, slug:, title:, edition:, stage:, doctype:, revdate:, files:, channels:, source: nil, metadata_formats: nil) ⇒ Publication
Returns a new instance of Publication.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/metanorma/release/publication.rb', line 71 def initialize(identifier:, slug:, title:, edition:, stage:, doctype:, revdate:, files:, channels:, source: nil, metadata_formats: nil) @identifier = identifier @slug = slug @title = title @edition = edition @stage = stage @doctype = doctype @revdate = revdate @files = files.freeze @channels = channels.freeze @source = source @metadata_formats = freeze end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
68 69 70 |
# File 'lib/metanorma/release/publication.rb', line 68 def channels @channels end |
#doctype ⇒ Object (readonly)
Returns the value of attribute doctype.
68 69 70 |
# File 'lib/metanorma/release/publication.rb', line 68 def doctype @doctype end |
#edition ⇒ Object (readonly)
Returns the value of attribute edition.
68 69 70 |
# File 'lib/metanorma/release/publication.rb', line 68 def edition @edition end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
68 69 70 |
# File 'lib/metanorma/release/publication.rb', line 68 def files @files end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
68 69 70 |
# File 'lib/metanorma/release/publication.rb', line 68 def identifier @identifier end |
#revdate ⇒ Object (readonly)
Returns the value of attribute revdate.
68 69 70 |
# File 'lib/metanorma/release/publication.rb', line 68 def revdate @revdate end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
68 69 70 |
# File 'lib/metanorma/release/publication.rb', line 68 def slug @slug end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
68 69 70 |
# File 'lib/metanorma/release/publication.rb', line 68 def source @source end |
#stage ⇒ Object (readonly)
Returns the value of attribute stage.
68 69 70 |
# File 'lib/metanorma/release/publication.rb', line 68 def stage @stage end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
68 69 70 |
# File 'lib/metanorma/release/publication.rb', line 68 def title @title end |
Class Method Details
.from_json(json_string) ⇒ Object
175 176 177 |
# File 'lib/metanorma/release/publication.rb', line 175 def self.from_json(json_string) PublicationSerializer.from_json(json_string) end |
.from_metadata_hash(data) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/metanorma/release/publication.rb', line 179 def self.(data) ident = data["identifier"] || data["id"] new( identifier: ident, slug: SlugStrategy.slug_from_identifier(ident), title: data["title"], edition: data["edition"], stage: data["stage"], doctype: data["doctype"], revdate: data["revdate"], files: [], channels: data["channels"] || [], source: nil, metadata_formats: data["formats"], ) end |
.from_release_body(body) ⇒ Object
171 172 173 |
# File 'lib/metanorma/release/publication.rb', line 171 def self.from_release_body(body) PublicationSerializer.from_release_body(body) end |
Instance Method Details
#base_dir ⇒ Object
91 92 93 |
# File 'lib/metanorma/release/publication.rb', line 91 def base_dir files.any? ? File.dirname(files.first.path) : "." end |
#content_hash(from_directory: nil) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/metanorma/release/publication.rb', line 95 def content_hash(from_directory: nil) dir = if from_directory && base_dir == "." from_directory else base_dir end ContentHash.of_directory(dir, base: slug) end |
#draft? ⇒ Boolean
108 109 110 |
# File 'lib/metanorma/release/publication.rb', line 108 def draft? DRAFT_STAGES.include?(stage.to_s) end |
#eql?(other) ⇒ Boolean
112 113 114 115 |
# File 'lib/metanorma/release/publication.rb', line 112 def eql?(other) other.is_a?(self.class) && identifier == other.identifier && edition == other.edition && stage == other.stage end |
#file?(format) ⇒ Boolean
104 105 106 |
# File 'lib/metanorma/release/publication.rb', line 104 def file?(format) formats.include?(format) end |
#formats ⇒ Object
87 88 89 |
# File 'lib/metanorma/release/publication.rb', line 87 def formats @metadata_formats || files.map(&:format) end |
#hash ⇒ Object
117 118 119 |
# File 'lib/metanorma/release/publication.rb', line 117 def hash [identifier, edition, stage].hash end |
#to_h ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/metanorma/release/publication.rb', line 121 def to_h h = { "id" => slug, "identifier" => identifier, "title" => title, "edition" => edition, "stage" => stage, "doctype" => doctype, "channels" => channels, "formats" => formats, "revdate" => revdate } h["source"] = source.to_h if source h["files"] = files.map(&:to_h) unless files.empty? h end |
#to_json(*_args) ⇒ Object
167 168 169 |
# File 'lib/metanorma/release/publication.rb', line 167 def to_json(*_args) PublicationSerializer.to_json(self) end |
#to_release_body ⇒ Object
163 164 165 |
# File 'lib/metanorma/release/publication.rb', line 163 def to_release_body PublicationSerializer.to_release_body(self) end |
#with_channels(new_channels) ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/metanorma/release/publication.rb', line 133 def with_channels(new_channels) self.class.new( identifier: identifier, slug: slug, title: title, edition: edition, stage: stage, doctype: doctype, revdate: revdate, files: files, channels: new_channels, source: source, metadata_formats: @metadata_formats ) end |
#with_files_and_source(new_files, release, repo) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/metanorma/release/publication.rb', line 143 def with_files_and_source(new_files, release, repo) source = PublicationSource.new( owner: repo.owner, repo: repo.repo, tag: release.tag_name, url: release.html_url, date: release.published_at ) pub_files = new_files.map do |f| name = File.basename(f) ext = File.extname(name).delete_prefix(".") PublicationFile.new(format: ext, name: name, path: f) end self.class.new( identifier: identifier, slug: slug, title: title, edition: edition, stage: stage, doctype: doctype, revdate: revdate, files: pub_files, channels: channels, source: source ) end |