Class: IsoDoc::Gb::Common

Inherits:
Common
  • Object
show all
Defined in:
lib/isodoc/gb/gbconvert.rb

Overview

A Converter implementation that generates GB output, and a document schema encapsulation of the document for validation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Common

Returns a new instance of Common.



13
14
15
16
17
18
# File 'lib/isodoc/gb/gbconvert.rb', line 13

def initialize(options)
  @meta = options[:meta]
  @standardlogoimg = options[:standardlogoimg]&.sub(%r{^(?=/|[A-Z]:/)}, "#{@localdir}/")
  @standardclassimg = options[:standardclassimg]&.sub(%r{^(?=/|[A-Z]:/)}, "#{@localdir}/")
  @standardissuerimg = options[:standardissuerimg]&.sub(%r{^(?=/|[A-Z]:/)}, "#{@localdir}/")
end

Instance Attribute Details

#metaObject

Returns the value of attribute meta.



11
12
13
# File 'lib/isodoc/gb/gbconvert.rb', line 11

def meta
  @meta
end

Instance Method Details

#fileloc(loc) ⇒ Object



20
21
22
# File 'lib/isodoc/gb/gbconvert.rb', line 20

def fileloc(loc)
  File.expand_path(File.join(File.dirname(__FILE__), loc))
end

#format_agency(agency, format, localdir) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/isodoc/gb/gbconvert.rb', line 24

def format_agency(agency, format, localdir)
  return "<img class='logo' src='#{@standardissuerimg}' alt='#{agency.join(",")}'></img>" if @standardissuerimg
  return agency unless agency.is_a?(Array)
  if agency == ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"]
     = "gb-issuer-default.gif"
    #FileUtils.cp fileloc(File.join('html/gb-logos', logo)), logo
    return "<img class='logo' src='#{fileloc(File.join('html/gb-logos', ))}' alt='#{agency.join(",")}'></img>"
  end
  format_agency1(agency, format)
end

#format_agency1(agency, format) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/isodoc/gb/gbconvert.rb', line 35

def format_agency1(agency, format)
  ret = "<table>"
  agency.each { |a| ret += "<tr><td>#{a}</td></tr>" }
  ret += "</table>"
  ret.gsub!(/<table>/, "<table width='100%'>") if format == :word
  ret
end

#format_logo(prefix, scope, _format, localdir) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/isodoc/gb/gbconvert.rb', line 43

def (prefix, scope, _format, localdir)
   = @meta.(prefix)
  return format_logo1(, prefix, scope, localdir) if @standardlogoimg
  return "" if %w(enterprise social-group).include? scope
  if .nil?
    "<span style='font-size:36pt;font-weight:bold'>#{prefix}</span>"
  else
    format_logo1(, prefix, scope, localdir)
  end
end

#format_logo1(logo, prefix, scope, localdir) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/isodoc/gb/gbconvert.rb', line 60

def format_logo1(, prefix, scope, localdir)
  local = local_logo_suffix(scope)
  return "<img class='logo' width='113' height='56' src='#{@standardlogoimg}' alt='#{prefix}'></img>"\
    "#{local}" if  @standardlogoimg
   += ".gif"
  #FileUtils.cp fileloc(File.join('html/gb-logos', logo)), logo
  #@files_to_delete << logo
  "<img class='logo' width='113' height='56' src='#{fileloc(File.join('html/gb-logos', ))}' alt='#{prefix}'></img>"\
    "#{local}"
end

#local_logo_suffix(scope) ⇒ Object



54
55
56
57
58
# File 'lib/isodoc/gb/gbconvert.rb', line 54

def local_logo_suffix(scope)
  return "" if scope != "local"
  local = @meta.get[:gblocalcode]
  "<span style='font-weight:bold'>#{local}</span>"
end