junoser 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/junoser/ruler.rb CHANGED
@@ -54,7 +54,7 @@ module Junoser
54
54
  str.gsub! '"as-path-prepend" arg', '"as-path-prepend" (quote | arg)'
55
55
  str.gsub! '"path-list" arg (', 'b(ipaddr,'
56
56
 
57
- str.gsub!(/(s\(\s*)"address" \(\s*arg\s*\)/) { "#{$1}arg" }
57
+ str.gsub!(/(s\(\s*)"address" arg/) { "#{$1}arg" }
58
58
  str.gsub!(/^(\s*"idle-timeout" \(\s*c\(\s*c\(\s*"forever",\s*)"timeout" arg/) { "#{$1}arg" }
59
59
 
60
60
  str = omit_label(str, 'contents', 'syslog_object')
@@ -87,7 +87,7 @@ module Junoser
87
87
  str.gsub!(/^(\s*"#{key}" \(\s*)c\(\s*arg,/) { "#{$1}sca(" }
88
88
  end
89
89
  %w[exact longer orlonger].each do |key|
90
- str.gsub!(/^(\s*"#{key}") \(\s*arg\s*\)/) { "#{$1}" }
90
+ str.gsub!(/^(\s*"#{key}") arg/) { "#{$1}" }
91
91
  end
92
92
 
93
93
  str.gsub!(/^(\s*)"inline-services"/) do
@@ -1,3 +1,3 @@
1
1
  module Junoser
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -16,16 +16,17 @@ module Junoser
16
16
  else
17
17
  raise "ERROR: unknown element: #{child.name}"
18
18
  end
19
- }.compact
19
+ }
20
20
  end
21
21
 
22
22
  def to_s
23
23
  case
24
24
  when config.empty?
25
+ ''
25
26
  when has_single_child_of?(Junoser::Xsd::Choice)
26
- format('c(', config.first.config.map(&:to_s).compact.join(",\n"), ')')
27
+ format('c(', config.first.config.map(&:to_s).join(",\n"), ')')
27
28
  else
28
- format('c(', config.map(&:to_s).compact.join(",\n"), ')')
29
+ format('c(', config.map(&:to_s).join(",\n"), ')')
29
30
  end
30
31
  end
31
32
  end
@@ -26,11 +26,11 @@ module Junoser
26
26
  else
27
27
  raise "ERROR: unknown element: #{child.name}"
28
28
  end
29
- }.compact
29
+ }
30
30
  end
31
31
 
32
32
  def to_s
33
- str = config.map {|c| c.is_a?(String) ? format(OFFSET + c) : c.to_s }.compact.join("\n")
33
+ str = config.map {|c| c.is_a?(String) ? format(OFFSET + c) : c.to_s }.join("\n")
34
34
 
35
35
  str = case [!argument.nil?, !str.empty?]
36
36
  when [true, true]
@@ -9,7 +9,7 @@ module Junoser
9
9
 
10
10
  def initialize(xml, options={})
11
11
  super
12
- @argument = find_name_element || find_single_simple_type || find_simple_type_attribute
12
+ @argument = find_name_element || find_type_attribute
13
13
  end
14
14
 
15
15
  def config
@@ -22,37 +22,30 @@ module Junoser
22
22
  else
23
23
  raise "ERROR: unknown element: #{child.name}"
24
24
  end
25
- }.compact
25
+ }
26
26
  end
27
27
 
28
28
  def to_s
29
- str = config.map {|c| c.is_a?(String) ? format(OFFSET + c) : c.to_s }.compact.join("\n")
30
-
31
29
  str = case
32
- when str.empty? && xml['type']
33
- l = label ? "#{label} (" : '('
34
- format(l, format(OFFSET + xml['type'].underscore), ')')
35
- when str.empty?
30
+ when content.empty?
36
31
  format(label)
32
+ when content =~ /^ *arg$/
33
+ format("#{label} arg")
34
+ when label
35
+ format("#{label} (", content, ')')
37
36
  else
38
- l = label ? "#{label} (" : '('
39
- format(l, str, ')')
37
+ format('(', content, ')')
40
38
  end
41
39
 
42
40
  oneliner? ? "#{str}.as(:oneline)" : str
43
41
  end
44
42
 
45
43
  def content
46
- str = config.map {|c| c.is_a?(String) ? format(OFFSET + c) : c.to_s }.compact.join("\n")
47
-
48
- case
49
- when str.empty? && xml['type']
50
- format(OFFSET + xml['type'].underscore)
51
- when str.empty?
52
- ''
53
- else
54
- str
55
- end
44
+ @content ||= if config.empty?
45
+ xml['type'] ? format(OFFSET + xml['type'].underscore) : ''
46
+ else
47
+ config.map {|c| c.is_a?(String) ? format(OFFSET + c) : c.to_s }.join("\n")
48
+ end
56
49
  end
57
50
 
58
51
 
@@ -83,13 +76,7 @@ module Junoser
83
76
  xml.xpath('./xsd:complexType/xsd:sequence/xsd:element[@name="name"]').remove.first
84
77
  end
85
78
 
86
- def find_single_simple_type
87
- simples = xml.xpath('./xsd:simpleType').remove
88
- raise "ERROR: Element shouldn't have simpleType child and another" if simples.size > 1
89
- simples.first
90
- end
91
-
92
- def find_simple_type_attribute
79
+ def find_type_attribute
93
80
  if xml['type'] =~ /^xsd:.*/
94
81
  xml.remove_attribute 'type'
95
82
  'arg'
@@ -12,11 +12,11 @@ module Junoser
12
12
  def config
13
13
  raise "ERROR: unknown Enumeration format" if children.size > 1
14
14
 
15
- has_match? ? 'arg' : %["#{xml['value']}"]
15
+ has_match? ? ['arg'] : [%["#{xml['value']}"]]
16
16
  end
17
17
 
18
18
  def to_s
19
- format(OFFSET + config)
19
+ format(OFFSET + config.first)
20
20
  end
21
21
 
22
22
 
@@ -20,13 +20,13 @@ module Junoser
20
20
  else
21
21
  raise "ERROR: unknown element: #{child.name}"
22
22
  end
23
- }.compact
23
+ }
24
24
  end
25
25
 
26
26
  def to_s
27
27
  return format('arg') if config.empty?
28
28
 
29
- str = '(' + config.map {|c| c.to_s.strip }.compact.join(' | ') + ')'
29
+ str = '(' + config.map {|c| c.to_s.strip }.join(' | ') + ')'
30
30
  format(str)
31
31
  end
32
32
  end
@@ -19,7 +19,7 @@ module Junoser
19
19
  else
20
20
  raise "ERROR: unknown element: #{child.name}"
21
21
  end
22
- }.compact
22
+ }
23
23
  end
24
24
 
25
25
  def to_s
@@ -27,10 +27,10 @@ module Junoser
27
27
  when config.empty?
28
28
  when has_single_child_of?(Junoser::Xsd::Choice)
29
29
  child = config.first
30
- str = child.config.map(&:to_s).compact.join(",\n")
30
+ str = child.config.map(&:to_s).reject(&:empty?).join(",\n")
31
31
  format('c(', str, ')') unless str.empty?
32
32
  else
33
- str = config.map {|c| c.is_a?(String) ? format(OFFSET + c) : c.to_s }.compact.join(",\n")
33
+ str = config.map {|c| c.is_a?(String) ? format(OFFSET + c) : c.to_s }.reject(&:empty?).join(",\n")
34
34
  format('s(', str, ')')
35
35
  end
36
36
  end
@@ -16,7 +16,7 @@ module Junoser
16
16
  else
17
17
  raise "ERROR: unknown element: #{child.name}"
18
18
  end
19
- }.compact
19
+ }
20
20
  end
21
21
 
22
22
  def to_s
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junoser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shintaro Kojima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-25 00:00:00.000000000 Z
11
+ date: 2016-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet