Class: Idcf::Cli::Lib::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/idcf/cli/lib/document.rb

Overview

document

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.regionObject (readonly)

Returns the value of attribute region.



9
10
11
# File 'lib/idcf/cli/lib/document.rb', line 9

def region
  @region
end

.versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/idcf/cli/lib/document.rb', line 9

def version
  @version
end

Class Method Details

.init(region: '', version: '') ⇒ Object



11
12
13
14
# File 'lib/idcf/cli/lib/document.rb', line 11

def init(region: '', version: '')
  @region  = region
  @version = version
end

.make_document_desc(link) ⇒ Object



16
17
18
# File 'lib/idcf/cli/lib/document.rb', line 16

def make_document_desc(link)
  "reference : #{make_document_url(link)}"
end

.make_document_id(link) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/idcf/cli/lib/document.rb', line 29

def make_document_id(link)
  titles      = link.parent_titles
  service_str = titles.shift.downcase
  version_str = "#{Idcf::Cli::Conf::Const::DOCUMENT_SPACE_CONVERSION}#{@version}"
  version_str = (@region.present? && @region != 'default' ? '' : version_str)
  id_format   = Idcf::Cli::Conf::Const::DOCUMENT_ID_PREFIX_FORMAT
  prefix      = format(id_format, service: service_str, version: version_str)
  results     = [prefix]
  results.concat(titles)
  result = results.join(Idcf::Cli::Conf::Const::DOCUMENT_ID_SEP)
  result.gsub(/ /, Idcf::Cli::Conf::Const::DOCUMENT_SPACE_CONVERSION)
end

.make_document_url(link) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/idcf/cli/lib/document.rb', line 20

def make_document_url(link)
  result       = URI(Idcf::Cli::Conf::Const::DOCUMENT_URL)
  add_params   = {
    'id' => make_document_id(link)
  }.to_param
  result.query = result.query ? "#{result.query}&#{add_params}" : add_params
  result.to_s
end