Class: Metanorma::Release::AggregatedDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/release/document_index.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, title:, edition:, stage:, doctype:, channels:, formats:, flavor:, content_hash:, source:, files:) ⇒ AggregatedDocument

Returns a new instance of AggregatedDocument.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/metanorma/release/document_index.rb', line 55

def initialize(id:, title:, edition:, stage:, doctype:, channels:,
               formats:, flavor:, content_hash:, source:, files:)
  @id = id
  @title = title
  @edition = edition
  @stage = stage
  @doctype = doctype
  @channels = channels.freeze
  @formats = formats.freeze
  @flavor = flavor
  @content_hash = content_hash
  @source = source
  @files = files.freeze
  freeze
end

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



52
53
54
# File 'lib/metanorma/release/document_index.rb', line 52

def channels
  @channels
end

#content_hashObject (readonly)

Returns the value of attribute content_hash.



52
53
54
# File 'lib/metanorma/release/document_index.rb', line 52

def content_hash
  @content_hash
end

#doctypeObject (readonly)

Returns the value of attribute doctype.



52
53
54
# File 'lib/metanorma/release/document_index.rb', line 52

def doctype
  @doctype
end

#editionObject (readonly)

Returns the value of attribute edition.



52
53
54
# File 'lib/metanorma/release/document_index.rb', line 52

def edition
  @edition
end

#filesObject (readonly)

Returns the value of attribute files.



52
53
54
# File 'lib/metanorma/release/document_index.rb', line 52

def files
  @files
end

#flavorObject (readonly)

Returns the value of attribute flavor.



52
53
54
# File 'lib/metanorma/release/document_index.rb', line 52

def flavor
  @flavor
end

#formatsObject (readonly)

Returns the value of attribute formats.



52
53
54
# File 'lib/metanorma/release/document_index.rb', line 52

def formats
  @formats
end

#idObject (readonly)

Returns the value of attribute id.



52
53
54
# File 'lib/metanorma/release/document_index.rb', line 52

def id
  @id
end

#sourceObject (readonly)

Returns the value of attribute source.



52
53
54
# File 'lib/metanorma/release/document_index.rb', line 52

def source
  @source
end

#stageObject (readonly)

Returns the value of attribute stage.



52
53
54
# File 'lib/metanorma/release/document_index.rb', line 52

def stage
  @stage
end

#titleObject (readonly)

Returns the value of attribute title.



52
53
54
# File 'lib/metanorma/release/document_index.rb', line 52

def title
  @title
end

Class Method Details

.from_h(hash) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/metanorma/release/document_index.rb', line 33

def self.from_h(hash)
  files = (hash['files'] || []).map do |f|
    DocumentFile.new(name: f['name'], path: f['path'])
  end
  source_data = hash['source'] || {}
  source = DocumentSource.new(
    owner: source_data['owner'], repo: source_data['repo'],
    tag: source_data['tag'], release_url: source_data['releaseUrl'],
    release_date: source_data['releaseDate']
  )
  new(
    id: hash['id'], title: hash['title'], edition: hash['edition'],
    stage: hash['stage'], doctype: hash.fetch('doctype', ''),
    channels: hash['channels'] || [], formats: hash['formats'] || [],
    flavor: hash['flavor'], content_hash: hash['contentHash'],
    source: source, files: files
  )
end

Instance Method Details

#to_hObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/metanorma/release/document_index.rb', line 71

def to_h
  {
    'id' => id, 'title' => title, 'edition' => edition,
    'stage' => stage, 'doctype' => doctype,
    'channels' => channels, 'formats' => formats,
    'flavor' => flavor, 'contentHash' => content_hash,
    'source' => {
      'owner' => source.owner, 'repo' => source.repo,
      'tag' => source.tag, 'releaseUrl' => source.release_url,
      'releaseDate' => source.release_date
    },
    'files' => files.map { |f| { 'name' => f.name, 'path' => f.path } }
  }
end