Class: Presenter::Xsd

Inherits:
Object
  • Object
show all
Defined in:
lib/presenter/xsd.rb

Instance Method Summary collapse

Instance Method Details

#get_enums_by_type(domain_arguments) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/presenter/xsd.rb', line 3

def get_enums_by_type(domain_arguments)
  xsd_files_gateway = ViewModelGateway::XsdFilesGateway.new(domain_arguments)

  begin
    xsd_files = xsd_files_gateway.xsd_files
  rescue ViewModelBoundary::XsdFilesNotFound => e
    raise ViewModelBoundary::XsdFilesNotFound, e.message.to_s
  end

  hash = {}

  xsd_files.each do |file|
    enums_hash = File.extname(file).downcase == ".xsd" ? read_xsd(file, domain_arguments.simple_type) : read_xml(file, domain_arguments.simple_type, domain_arguments.node_hash)

    next if enums_hash.empty?

    hash[xsd_files_gateway.schema_version(file)] = enums_hash
  end

  raise ViewModelBoundary::NodeNotFound, "Node #{domain_arguments.simple_type} was not found in any of the files in #{domain_arguments.xsd_dir_path} directory" if hash.empty?

  hash
end

#unique_enums(domain_arguments) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/presenter/xsd.rb', line 27

def unique_enums(domain_arguments)
  uniq_enums = []
  enums = get_enums_by_type(domain_arguments).values

  enums.each_with_index do |_hash, i|
    if i.positive? && (enums[i].to_a != enums[i + 1].to_a)
      uniq_enums << enums[i]
    end
  end
  uniq_enums
end

#variation_between_schema_versions?(enums_hash) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/presenter/xsd.rb', line 39

def variation_between_schema_versions?(enums_hash)
  enums_hash.values.flatten.uniq.count != 1
end