Module: LUSI::API::Core::XML

Defined in:
lib/lusi_api/core/xml.rb

Constant Summary collapse

NAMESPACE =
'Uol.Cis.Lusi.WebService'

Class Method Summary collapse

Class Method Details

.lookup(xml = nil, lookup = nil, service = nil, path = nil, default = nil) {|result| ... } ⇒ Object

Yields:

  • (result)


12
13
14
15
16
17
18
# File 'lib/lusi_api/core/xml.rb', line 12

def self.lookup(xml = nil, lookup = nil, service = nil,  path = nil, default = nil, &block)
  return default if xml.nil? || lookup.nil? || service.nil?
  key = xml_content_at(xml, path)
  result = lookup.lookup(service, key, default)
  yield(result) if block_given?
  result
end

.xml(xml = nil, path = nil, default = nil, filter: nil, &block) ⇒ Object



20
21
22
# File 'lib/lusi_api/core/xml.rb', line 20

def self.xml(xml = nil, path = nil, default = nil, filter: nil, &block)
  _xml(xml, path, default, single: false, content: false, filter: filter, &block)
end

.xml_at(xml = nil, path = nil, default = nil, &block) ⇒ Object



24
25
26
# File 'lib/lusi_api/core/xml.rb', line 24

def self.xml_at(xml = nil, path = nil, default = nil, &block)
  _xml(xml, path, default, single: true, content: false, &block)
end

.xml_boolean(xml = nil, path = nil, default = nil, &block) ⇒ Object



28
29
30
31
# File 'lib/lusi_api/core/xml.rb', line 28

def self.xml_boolean(xml = nil, path = nil, default = nil, &block)
  content = xml_content(xml, path, default)
  content.map { |str| xml_boolean_parse(str, default) }
end

.xml_boolean_at(xml = nil, path = nil, default = nil, &block) ⇒ Object



33
34
35
# File 'lib/lusi_api/core/xml.rb', line 33

def self.xml_boolean_at(xml = nil, path = nil, default = nil, &block)
  xml_boolean_parse(xml_content_at(xml, path, default), default)
end

.xml_boolean_parse(boolstr = nil, default = nil, true_values = nil, false_values = nil, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lusi_api/core/xml.rb', line 37

def self.xml_boolean_parse(boolstr = nil, default = nil, true_values = nil, false_values = nil, &block)
  boolstr = boolstr.to_s.downcase
  false_values ||= ['false', 'n', 'no']
  true_values ||= ['true', 'y', 'yes']
  if true_values.include?(boolstr)
    true
  elsif false_values.include?(boolstr)
    false
  else
    default
  end
end

.xml_content(xml = nil, path = nil, default = nil, &block) ⇒ Object



50
51
52
# File 'lib/lusi_api/core/xml.rb', line 50

def self.xml_content(xml = nil, path = nil, default = nil, &block)
  _xml(xml, path, default, single: false, content: true, &block)
end

.xml_content_at(xml = nil, path = nil, default = nil, &block) ⇒ Object



54
55
56
# File 'lib/lusi_api/core/xml.rb', line 54

def self.xml_content_at(xml = nil, path = nil, default = nil, &block)
  _xml(xml, path, default, single: true, content: true, &block)
end

.xml_datetime(xml = nil, path = nil, default = nil, format = nil, &block) ⇒ Object



58
59
60
61
# File 'lib/lusi_api/core/xml.rb', line 58

def self.xml_datetime(xml = nil, path = nil, default = nil, format = nil, &block)
  content = xml_content(xml, path, default)
  content.map { |str| xml_datetime_parse(str, default, format) }
end

.xml_datetime_at(xml = nil, path = nil, default = nil, format = nil, &block) ⇒ Object



63
64
65
# File 'lib/lusi_api/core/xml.rb', line 63

def self.xml_datetime_at(xml = nil, path = nil, default = nil, format = nil, &block)
  xml_datetime_parse(xml_content_at(xml, path, default), default, format)
end

.xml_datetime_parse(datestr = nil, default = nil, format = nil, &block) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/lusi_api/core/xml.rb', line 67

def self.xml_datetime_parse(datestr = nil, default = nil, format = nil, &block)
  return default if datestr.nil?
  format ||= '%Y-%m-%dT%H:%M:%S'
  begin
    DateTime.strptime(datestr, format)
  rescue Exception
    default
  end
end

.xml_float(xml = nil, path = nil, default = nil, &block) ⇒ Object



77
78
79
80
# File 'lib/lusi_api/core/xml.rb', line 77

def self.xml_float(xml = nil, path = nil, default = nil, &block)
  content = xml_content(xml, path, default)
  content.map { |str| xml_float_parse(str, default) }
end

.xml_float_at(xml = nil, path = nil, default = nil, &block) ⇒ Object



82
83
84
# File 'lib/lusi_api/core/xml.rb', line 82

def self.xml_float_at(xml = nil, path = nil, default = nil, &block)
  xml_float_parse(xml_content_at(xml, path, default), default)
end

.xml_float_parse(floatstr, default = nil) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/lusi_api/core/xml.rb', line 86

def self.xml_float_parse(floatstr, default = nil)
  begin
    floatstr.to_f
  rescue
    default
  end
end

.xml_int(xml = nil, path = nil, default = nil, &block) ⇒ Object



94
95
96
97
# File 'lib/lusi_api/core/xml.rb', line 94

def self.xml_int(xml = nil, path = nil, default = nil, &block)
  content = xml_content(xml, path, default)
  content.map { |str| xml_int_parse(str, default) }
end

.xml_int_at(xml = nil, path = nil, default = nil, &block) ⇒ Object



99
100
101
# File 'lib/lusi_api/core/xml.rb', line 99

def self.xml_int_at(xml = nil, path = nil, default = nil, &block)
  xml_int_parse(xml_content_at(xml, path, default), default)
end

.xml_int_parse(intstr, default = nil) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/lusi_api/core/xml.rb', line 103

def self.xml_int_parse(intstr, default = nil)
  begin
    intstr.to_i
  rescue
    default
  end
end