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.

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



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:



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>



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



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.



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

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

#specification_versionString



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

def_delegator :@source_documents, :specification_version

#transmission_tablesArray<TransmissionTable>



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

def transmission_tables
  @transmission_tables ||= read_transmission_tables
end

#typesArray<VariableType>



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

def types
  @types ||= read_types
end

#versionString



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

def_delegator :@source_documents, :version

#xsdNokogiri::XML::Document



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

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