Class: NcsNavigator::Mdes::Specification

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ncs_navigator/mdes/specification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, options = {}) ⇒ Specification

Returns a new instance of Specification.

Parameters:

Options Hash (options):

  • :log (Object)

    a logger to use while reading the specification. If not specified, a logger pointing to standard error will be used.



36
37
38
39
40
41
42
43
44
# File 'lib/ncs_navigator/mdes/specification.rb', line 36

def initialize(version, options={})
  @source_documents = case version
                      when SourceDocuments
                        version
                      else
                        SourceDocuments.get(version)
                      end
  @log = options[:log] || NcsNavigator::Mdes.default_logger
end

Instance Attribute Details

#source_documentsSourceDocuments

Returns the source documents this reader is working from.

Returns:



15
16
17
# File 'lib/ncs_navigator/mdes/specification.rb', line 15

def source_documents
  @source_documents
end

Instance Method Details

#[](table_name) ⇒ TransmissionTable? #[](pattern) ⇒ Array<TransmissionTable>

A shortcut for accessing particular #transmission_tables.

Overloads:

  • #[](table_name) ⇒ TransmissionTable?

    Retrieves a single table by name.

    Parameters:

    • table_name (String)

      the transmission table to return.

    Returns:

  • #[](pattern) ⇒ Array<TransmissionTable>

    Searches the transmission tables by name.

    Parameters:

    • pattern (Regexp)

      the pattern to match the name against.

    Returns:



148
149
150
151
152
153
154
155
156
157
# File 'lib/ncs_navigator/mdes/specification.rb', line 148

def [](criterion)
  case criterion
  when Regexp
    transmission_tables.select { |t| t.name =~ criterion }
  when String
    transmission_tables.detect { |t| t.name == criterion }
  else
    fail "Unexpected criterion #{criterion.inspect}"
  end
end

#diff(other, options = {}) ⇒ Object



208
209
210
# File 'lib/ncs_navigator/mdes/specification.rb', line 208

def diff(other, options={})
  Differences::Entry.compute(self, other, DIFF_CRITERIA, options)
end

#disposition_codesArray<DispositionCode>

Returns all the named disposition codes in the MDES.

Returns:

  • (Array<DispositionCode>)

    all the named disposition codes in the MDES.



175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ncs_navigator/mdes/specification.rb', line 175

def disposition_codes
  @disposition_codes ||=
    begin
      if File.exist?(source_documents.disposition_codes)
        YAML.load(File.read source_documents.disposition_codes).collect do |dc|
          DispositionCode.new(dc)
        end
      else
        empty_disposition_codes
      end
    end
end

#heuristic_overridesHash

Returns the loaded heuristic overrides, or a default (empty) set.

Returns:

  • (Hash)

    the loaded heuristic overrides, or a default (empty) set



56
57
58
59
60
61
62
63
64
65
# File 'lib/ncs_navigator/mdes/specification.rb', line 56

def heuristic_overrides
  @heuristic_overrides ||=
    begin
      if File.exist?(source_documents.heuristic_overrides)
        empty_overrides.merge(YAML.load(File.read source_documents.heuristic_overrides))
      else
        empty_overrides
      end
    end
end

#inspectString

A briefer inspection for nicer IRB sessions.

Returns:

  • (String)


197
198
199
# File 'lib/ncs_navigator/mdes/specification.rb', line 197

def inspect
  "#<#{self.class} version=#{version.inspect}>"
end

#specification_versionString

Returns the exact version this specification matches. It may be more exact than the requested version due to applied patches.

Returns:

  • (String)

    the exact version this specification matches. It may be more exact than the requested version due to applied patches.



27
# File 'lib/ncs_navigator/mdes/specification.rb', line 27

def_delegator :@source_documents, :specification_version

#transmission_tablesArray<TransmissionTable>

Returns all the transmission tables in this version of the MDES.

Returns:

  • (Array<TransmissionTable>)

    all the transmission tables in this version of the MDES.



77
78
79
# File 'lib/ncs_navigator/mdes/specification.rb', line 77

def transmission_tables
  @transmission_tables ||= read_transmission_tables
end

#typesArray<VariableType>

Returns all the named types in the MDES. This includes all the code lists.

Returns:

  • (Array<VariableType>)

    all the named types in the MDES. This includes all the code lists.



162
163
164
# File 'lib/ncs_navigator/mdes/specification.rb', line 162

def types
  @types ||= read_types
end

#versionString

Returns the version of the MDES to which this instance refers.

Returns:

  • (String)

    the version of the MDES to which this instance refers.



20
# File 'lib/ncs_navigator/mdes/specification.rb', line 20

def_delegator :@source_documents, :version

#xsdNokogiri::XML::Document

Returns the parsed version of the VDR XML schema for this version of the MDES.

Returns:

  • (Nokogiri::XML::Document)

    the parsed version of the VDR XML schema for this version of the MDES.



49
50
51
# File 'lib/ncs_navigator/mdes/specification.rb', line 49

def xsd
  @xsd ||= Nokogiri::XML(File.read source_documents.schema)
end