Class: RelatonIec::IecBibliographicItem

Inherits:
RelatonIsoBib::IsoBibliographicItem
  • Object
show all
Defined in:
lib/relaton_iec/iec_bibliographic_item.rb

Constant Summary collapse

SUBDOCTYPES =
%w[specification method-of-test vocabulary code-of-practice].freeze
FUNCTION =
%w[emc safety enviroment quality-assurance].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ IecBibliographicItem

Initialize instance of RelatonIec::IecBibliographicItem

Parameters:

  • **args (Hash)

    hash of attributes

  • args (Hash)

    a customizable set of options

Options Hash (**args):

  • :function (String, nil)

    function

  • :updates_document_type (String, nil)

    updates document type

  • :price_code (String, nil)

    price code

  • :cen_processing (Boolean, nil)
  • :secretary (String, nil)
  • :secretary (String, nil)

    secretary

  • :interest_to_committees (String, nil)

    interest to committees

  • :accessibility_color_inside (Boolean, nil)

    accessibility color inside



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 29

def initialize(**args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  if args[:function] && !FUNCTION.include?(args[:function])
    Util.warn do
      "Invalid function: `#{args[:function]}`\n" \
      "Allowed function values are: `#{FUNCTION.join('`, `')}`"
    end
  end
  if args[:updates_document_type] &&
      !DocumentType::DOCTYPES.include?(args[:updates_document_type])
    Util.warn do
      "WARNING: Invalid updates_document_type: `#{args[:updates_document_type]}`\n" \
      "Allowed updates_document_type values are: `#{DocumentType::DOCTYPES.join('`, `')}`"
    end
  end
  @function = args.delete :function
  @updates_document_type = args.delete :updates_document_type
  @accessibility_color_inside = args.delete :accessibility_color_inside
  @cen_processing = args.delete :cen_processing
  @secretary = args.delete :secretary
  @interest_to_committees = args.delete :interest_to_committees
  super
end

Instance Attribute Details

#accessibility_color_insideBoolean? (readonly)

Returns:

  • (Boolean, nil)


12
13
14
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 12

def accessibility_color_inside
  @accessibility_color_inside
end

#cen_processingBoolean? (readonly)

Returns:

  • (Boolean, nil)


12
13
14
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 12

def cen_processing
  @cen_processing
end

#functionString? (readonly)

Returns:

  • (String, nil)


8
9
10
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 8

def function
  @function
end

#interest_to_committeesString? (readonly)

Returns:

  • (String, nil)


8
9
10
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 8

def interest_to_committees
  @interest_to_committees
end

#secretaryString? (readonly)

Returns:

  • (String, nil)


8
9
10
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 8

def secretary
  @secretary
end

#updates_document_typeString? (readonly)

Returns:

  • (String, nil)


8
9
10
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 8

def updates_document_type
  @updates_document_type
end

Class Method Details

.from_hash(hash) ⇒ RelatonIsoBib::IecBibliographicItem

Parameters:

  • hash (Hash)

Returns:

  • (RelatonIsoBib::IecBibliographicItem)


63
64
65
66
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 63

def self.from_hash(hash)
  item_hash = ::RelatonIec::HashConverter.hash_to_bib(hash)
  new(**item_hash)
end

Instance Method Details

#ext_schemaString

Fetch flavor schema version

Returns:

  • (String)

    schema version



57
58
59
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 57

def ext_schema
  schema_versions["relaton-model-iec"]
end

#has_ext?Boolean

Returns:

  • (Boolean)


120
121
122
123
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 120

def has_ext?
  super || function || updates_document_type || !accessibility_color_inside.nil? ||
    !cen_processing.nil? || secretary || interest_to_committees
end

#to_hash(embedded: false) ⇒ Hash

Returns:

  • (Hash)


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 103

def to_hash(embedded: false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  hash = super
  hash["ext"]["function"] = function if function
  if updates_document_type
    hash["ext"]["updates_document_type"] = updates_document_type
  end
  unless accessibility_color_inside.nil?
    hash["ext"]["accessibility_color_inside"] = accessibility_color_inside
  end
  hash["ext"]["cen_processing"] = cen_processing unless cen_processing.nil?
  hash["ext"]["secretary"] = secretary if secretary
  if interest_to_committees
    hash["ext"]["interest_to_committees"] = interest_to_committees
  end
  hash
end

#to_xml(**opts) ⇒ String

Returns XML.

Parameters:

  • opts (Hash)

Options Hash (**opts):

  • :builder (Nokogiri::XML::Builder)

    XML builder

  • :bibdata (Boolean)
  • :lang (String)

    language

Returns:

  • (String)

    XML



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/relaton_iec/iec_bibliographic_item.rb', line 73

def to_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  super(**opts) do |b|
    if opts[:bibdata]
      ext = b.ext do
        doctype&.to_xml b
        b.horizontal horizontal unless horizontal.nil?
        b.function function if function
        editorialgroup&.to_xml b
        ics.each { |i| i.to_xml b }
        structuredidentifier&.to_xml b
        b.stagename stagename if stagename
        if updates_document_type
          b.send(:"updates-document-type", updates_document_type)
        end
        unless accessibility_color_inside.nil?
          b.send(:"accessibility-color-inside", accessibility_color_inside)
        end
        b.send(:"price-code", price_code) if price_code
        b.send(:"cen-processing", cen_processing) unless cen_processing.nil?
        b.secretary secretary if secretary
        if interest_to_committees
          b.send(:"interest-to-committees", interest_to_committees)
        end
      end
      ext["schema-version"] = ext_schema unless opts[:embedded]
    end
  end
end