@@ -105,21 +105,21 @@ def to_ruby
105105 if code
106106 "#{ code } ? :#{ key } : #{ result } "
107107 else
108- ":" << key . to_s
108+ ":#{ key } "
109109 end
110110 end + " }"
111111 end
112112 end
113113
114114 class Proposition < Array
115- def initialize ( type = nil )
115+ def initialize ( type )
116116 super ( )
117117
118118 @type = type
119119 end
120120
121121 def to_ruby
122- @ruby ||= "(" << map ( &:to_ruby ) . join ( " #{ @type } " ) << " )"
122+ @ruby ||= "(#{ map ( &:to_ruby ) . join ( " #{ @type } " ) } )"
123123 end
124124 end
125125
@@ -156,71 +156,75 @@ def to_ruby
156156 @ruby ||= begin
157157 enclose = false
158158 fraction = false
159- case @type
159+
160+ op = case @type
160161 when "i"
161- op = "n.to_i"
162+ "n.to_i"
162163 when "f"
163- op = '(f = n.to_s.split(".")[1]) ? f.to_i : 0'
164164 enclose = true
165+ '(f = n.to_s.split(".")[1]) ? f.to_i : 0'
165166 when "t"
166- op = '(t = n.to_s.split(".")[1]) ? t.gsub(/0+$/, "").to_i : 0'
167167 enclose = true
168+ '(t = n.to_s.split(".")[1]) ? t.gsub(/0+$/, "").to_i : 0'
168169 when "v"
169- op = '(v = n.to_s.split(".")[1]) ? v.length : 0'
170170 enclose = true
171+ '(v = n.to_s.split(".")[1]) ? v.length : 0'
171172 when "w"
172- op = '(w = n.to_s.split(".")[1]) ? w.gsub(/0+$/, "").length : 0'
173173 enclose = true
174+ '(w = n.to_s.split(".")[1]) ? w.gsub(/0+$/, "").length : 0'
174175 when "c" , "e"
175176 # We don't support numbers in the "compact decimal" format.
176177 # Since `c`/`e` are always 0 for non-"compact decimal" format
177178 # numbers, we just hardcode it to 0 for now.
178179 # TODO: https://github.com/ruby-i18n/ruby-cldr/issues/131
179- op = "#{ @type } = 0"
180180 enclose = true
181+ "#{ @type } = 0"
181182 when "n"
182183 fraction = true
183- op = "n.to_f"
184+ "n.to_f"
184185 else
185186 raise StandardError , "Unknown plural operand `#{ @type } `"
186187 end
188+
187189 if @mod
188- op = "(" << op << " )" if enclose
189- op << " % " << @mod . to_s
190+ op = "(#{ op } )" if enclose
191+ op = " #{ op } % #{ @mod } "
190192 enclose = false
191193 end
194+
192195 case @operator
193196 when :is
194- op = "(" << op << " )" if enclose
195- op << ( @negate ? " != " : " == " ) << @operand . to_s
197+ op = "(#{ op } )" if enclose
198+ op = " #{ op } #{ @negate ? "!= " : "==" } #{ @operand } "
196199 when :in
197200 values = @operand . first
198201 ranges = @operand . last
199202 prepend = ( @negate ? "!" : "" )
200203 str = ""
201204 bop = op
202- bop = "(" << bop << " )" if enclose || @mod
205+ bop = "(#{ bop } )" if enclose || @mod
203206 if values . count == 1
204- str = bop + ( @negate ? " != " : " == " ) << values . first . to_s
207+ str = " #{ bop } #{ @negate ? "!= " : "==" } #{ values . first } "
205208 elsif values . count > 1
206209 str = prepend + "#{ values . inspect } .include?(#{ op } )"
207210 end
208211 enclose = ranges . count > 1 || ( values . count > 0 && ranges . count > 0 )
209212 if ranges . count > 0
210- str << " || " if values . count > 0
211- str << "((#{ bop } % 1).zero? && " if fraction
212- str << "(" if ranges . count > 1
213- str << prepend + "(#{ ranges . shift . inspect } ).include?(#{ op } )"
214- ranges . each do |range |
215- str << " || " << prepend + "(#{ range . inspect } ).include?(#{ op } )"
216- end
217- str << ")" if ranges . count > 0
218- str << ")" if fraction
213+ str += " || " if values . count > 0
214+ str += "((#{ bop } % 1).zero? && " if fraction
215+
216+ ranges_formatted = ranges . map do |range |
217+ "#{ prepend } (#{ range . inspect } ).include?(#{ op } )"
218+ end . join ( " || " )
219+ ranges_formatted = "(#{ ranges_formatted } )" if ranges . count > 1
220+ str += ranges_formatted
221+
222+ str += ")" if fraction
219223 end
220- str = "(" << str << " )" if enclose
224+ str = "(#{ str } )" if enclose
221225 str
222226 when :within
223- op = "(" << op << " )" if enclose || @mod
227+ op = "(#{ op } )" if enclose || @mod
224228 ( @negate ? "!" : "" ) + "#{ op } .between?(#{ @operand . first } , #{ @operand . last } )"
225229 else
226230 raise "unknown operator '#{ @operator } '"
0 commit comments