Class: Stepmod::Utils::ExpressBibdata

Inherits:
Object
  • Object
show all
Defined in:
lib/stepmod/utils/express_bibdata.rb

Constant Summary collapse

DOCNUMBER =
10303

Instance Method Summary collapse

Constructor Details

#initialize(schema:) ⇒ ExpressBibdata

Returns a new instance of ExpressBibdata.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stepmod/utils/express_bibdata.rb', line 10

def initialize(schema:)
  # module, resource, application_protocol, business_object_model
  # @type = document.name

  # raise "UnknownFileError" unless %w(module resource
  #                                    application_protocol business_object_model).include?(@type)

  @published_info = schema.find("__published_in")&.remarks&.first
  @number = schema.find("__identifier")&.remarks&.first&.split("N")&.last
  @schema = schema

  if !published_info.nil?
    @pubid = Pubid::Iso::Identifier.parse(published_info)

    @part = pubid.part&.to_i
    @version = pubid.edition&.to_i
    @pub_year = pubid.year&.to_i
  elsif !schema.version.nil?
    @part = schema.version.items.find { |i| i.name == "part" }.value&.to_i
    @version = schema.version.items.find do |i|
                 i.name == "part"
               end.value&.to_i
    @pub_year = schema.version.items.find do |i|
                  i.name == "part"
                end.value&.to_i
  else
    raise "PublishedInfoNotFound"
  end

  @doctype = schema.find("__status")&.remarks&.first
  self
end

Instance Method Details

#anchorObject



102
103
104
# File 'lib/stepmod/utils/express_bibdata.rb', line 102

def anchor
  docid.gsub("/", "-").gsub(" ", "_").gsub(":", "_")
end

#docidObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/stepmod/utils/express_bibdata.rb', line 53

def docid
  no_date = case doctype
            when "IS"
              "ISO #{DOCNUMBER}-#{part}"
            when "WD"
              "ISO/WD #{DOCNUMBER}-#{part}"
            when "CD"
              "ISO/CD #{DOCNUMBER}-#{part}"
            when "DIS"
              "ISO/DIS #{DOCNUMBER}-#{part}"
            when "FDIS"
              "ISO/FDIS #{DOCNUMBER}-#{part}"
            when "TS"
              "ISO/TS #{DOCNUMBER}-#{part}"
            when "CD-TS"
              "ISO/CD TS #{DOCNUMBER}-#{part}"
            else
              "UNKNOWN DOCTYPE: (#{doctype})"
            end

  if pub_year
    "#{no_date}:#{pub_year}"
  else
    no_date
  end
end

#full_titleObject



97
98
99
100
# File 'lib/stepmod/utils/express_bibdata.rb', line 97

def full_title
  "Industrial automation systems and integration -- Product data" \
    " representation and exchange -- Part #{part}: #{part_title}"
end

#part_titleObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/stepmod/utils/express_bibdata.rb', line 80

def part_title
  case part
  when [200..299]
    "Application protocol: #{title_en}"
  when [300..399]
    "Abstract test suite: #{title_en}"
  when [400..499]
    "Application module: #{title_en}"
  when [500..599]
    "Application interpreted construct: #{title_en}"
  when [1000..1799]
    "Application module: #{title_en}"
  else
    title_en
  end
end

#title_enObject



43
44
45
46
47
48
49
50
51
# File 'lib/stepmod/utils/express_bibdata.rb', line 43

def title_en
  @title_en ||= @schema.find("__title")
                       .remarks
                       .first
                       .gsub("_", " ")
                       .capitalize
                       .gsub("2d", "2D")
                       .gsub("3d", "3D")
end

#to_mn_adocObject



106
107
108
109
110
111
112
# File 'lib/stepmod/utils/express_bibdata.rb', line 106

def to_mn_adoc
  if title_en
    "* [[[#{anchor},#{docid}]]], _#{full_title}_"
  else
    "* [[[#{anchor},#{docid}]]]"
  end
end