This file is indexed.

/usr/lib/ruby/vendor_ruby/merb-helpers/core_ext/numeric.rb is in ruby-merb-helpers 1.1.3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# -*- coding: utf-8 -*-
class Numeric
  module Transformer
    
    # known formats to use with the app
    # users can add their own formats by using Numeric::Transformer.add_format(:format_name => {})
    
    @formats ={
      :us => {
        :number => {      
          :precision => 3, 
          :delimiter => ',', 
          :separator => '.'
        },
        :currency => { 
          :unit => '$',
          :format => '%u%n',
          :precision => 2 
        }
      },
      :uk => {
        :number => {      
        :precision => 3, 
        :delimiter => ',', 
        :separator => '.'
        },
        :currency => { 
          :unit => '£',
          :format => '%u%n',
          :precision => 2 
        }
      },
      :au => {
        :number => {      
        :precision => 3, 
        :delimiter => ',', 
        :separator => '.'
        },
        :currency => { 
          :unit => '$',
          :format => '%u%n',
          :precision => 2 
        }
      },
      :fr => {
        :number => {      
        :precision => 3, 
        :delimiter => ' ', 
        :separator => ','
        },
        :currency => { 
          :unit => '€',
          :format => '%n%u',
          :precision => 2 
        }
      },
      :ru => { 
          :number => {
             :precision => 2,
             :delimiter => ' ',
             :separator => ','
             },
             :currency => {
               :unit => 'р.',
               :format => '%n %u',
               :precision => 2
             }
           }
    }
    
    # accessor for @formats
    #---
    # @private
    def self.formats
      @formats
    end
    
    @default_format = @formats[:us]
    
    
    # Accessor for the default format in use
    #
    #---
    # @public
    def self.default_format
      @default_format
    end
    
    
    # Changes the default format to use when transforming a +Numeric+ instance
    #
    # ==== Parameters
    # format_code <Symbol>:: format name to use as the new default format
    #
    # ==== Returns
    # Hash:: a hash representing the default format
    #
    #---
    # @public
    def self.change_default_format(format_code)
      @default_format = (formats[format_code] || default_format)
    end
    
    
    # Adds a new format to the existing transforming formats
    #
    # ==== Parameters
    # format <Hash>:: format defining how to transform numeric values
    #
    # ==== Examples
    #
    #
    #---
    # @public
    def self.add_format(format)
      formats.merge!(format)
      formats[format]
    end

    
    # Formats a +number+ with grouped thousands using +delimiter+ (e.g., 12,324). You can
    # pass another format to format the number differently.
    #
    #
    # ==== Parameters
    # format_name<Symbol>:: name of the format to use
    # options<Hash>:: options which will overwrite the used format
    #
    # ==== Returns
    # String:: a string representing the delimited number
    #
    # ==== Options
    # :delimiter - Overwrites the thousands delimiter.
    # :separator - Overwrites the separator between the units.
    #
    # ==== Examples
    # with_delimiter(12345678) # => 12,345,678
    # with_delimiter(12345678.05) # => 12,345,678.05
    # with_delimiter(12345678, :FR) # => 12.345.678
    # with_delimiter(12345678, :US) # => 12,345,678
    #
    #---
    # @private
    def self.with_delimiter(number, format_name = nil, options = {})
      
      format = (formats[format_name] || default_format)[:number].merge(options)

      begin
        parts = number.to_s.split('.')
        parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{format[:delimiter]}")
        parts.join(format[:separator])
      rescue
        number
      end
    end
    
    # Formats a +number+ with a level of <tt>:precision</tt> (e.g., 112.32 has a precision of 2).
    # You can pass another format to use and even overwrite the format's options.
    #
    #
    # ==== Parameters
    # format_name<Symbol>:: name of the format to use
    # options<Hash>:: options which will overwrite the used format
    #
    # ==== Returns
    # String:: a string representing the delimited number
    #
    # ==== Options
    # :precision - Overwrites the level of precision
    # :separator - Overwrites the separator between the units
    # :delimiter - Overwrites the thousands delimiter
    #
    # ==== Examples
    # with_precision(111.2345)                       # => 111.235
    # with_precision(111.2345, :UK, :precision => 1) # => "111.2"
    # with_precision(1234.567, :US, :precision => 1, :separator => ',', :delimiter => '-') # => "1-234,6"
    #
    #---
    # @private
    def self.with_precision(number, format_name = nil, options={})

      format = (formats[format_name] || default_format)[:number].merge(options)

      begin
        rounded_number = (Float(number) * (10 ** format[:precision])).round.to_f / 10 ** format[:precision]
        with_delimiter("%01.#{format[:precision]}f" % rounded_number, format_name, :delimiter => format[:delimiter], :separator => format[:separator])
      rescue
        number
      end
    end
    
    
    # Formats a +number+ into a currency string (e.g., $13.65). You can specify a format to use 
    # and even overwrite some of the format options.
    #
    # ==== Parameters
    # number<Numeric>:: Numeric value to convert
    # format_name<Symbol>:: name of the format to use
    # options<Hash>:: options which will overwrite the used format
    #
    # ==== Returns
    # String:: a string representing the number converted in currency
    #
    # ==== Options
    # :precision - Sets the level of precision 
    # :unit - Sets the denomination of the currency 
    # :format - Sets the format of the output string (defaults to "%u%n"). The field types are:
    #
    # %u The currency unit
    # %n The number
    #
    # ==== Examples
    # to_currency(1234567890.506, :US, :precision => 1)  # => "$1,234,567,890.5"
    # to_currency(1234567890.516, :FR)                   # =>"1 234 567 890,52€"
    # to_currency(1234567890.516, :US, :unit => "€")     # =>"€1,234,567,890.52"
    # to_currency(1234567890.506, :US, :precision => 3, :unit => "€") # => "€1,234,567,890.506"
    # to_currency(1234567890.506, :AU, :unit => "$AUD", :format => '%n %u') # => "1,234,567,890.51 $AUD"
    #
    #---
    # @private
    def self.to_currency(number, format_name = nil, options = {})
      
      format = (formats[format_name] || default_format)[:currency].merge(options)

      begin
        format[:format].gsub(/%n/, with_precision(number, 
                                      format_name, :precision  => format[:precision]) ).gsub(/%u/, format[:unit])
      rescue
        number
      end
    end
    
    
    # Formats a +number+ into a two digit string. Basically it prepends an integer to a 2 digits string.
    #
    # ==== Parameters
    # number<Numeric>:: Numeric value to convert
    #
    # ==== Returns
    # String:: a string representing the number converted into a 2 digits string.
    #
    # ==== Examples
    # two_digits(5-3) # => "02"
    #
    #---
    # @private
    def self.two_digits(number)
      (0..9).include?(number) ? "0#{number}" : number.to_s
    end

    # Converts a +numeric+ value representing minutes into a string representing an hour value
    #
    # ==== Parameters
    # number<Numeric>:: Numeric value representing minutes to convert in hours
    #
    # ==== Returns
    # String:: a string representing the numeric value converted in hours
    #
    # ==== Examples
    # minutes_to_hours(315) => "05:15"
    #
    #---
    # @private
    def self.minutes_to_hours(minutes)
      hours = (minutes/60).ceil
      minutes = (minutes - (hours * 60)).to_i
      "#{two_digits(hours)}:#{two_digits(minutes)}"
    end

  end #of Numeric::Transformer
 
  # Formats with with grouped thousands using +delimiter+ (e.g., 12,324). You can
  # pass another format to format the number differently.
  #
  #
  # ==== Parameters
  # format_name<Symbol>:: name of the format to use
  # options<Hash>:: options which will overwrite the used format
  #
  # ==== Returns
  # String:: a string representing the delimited number
  #
  # ==== Options
  # :delimiter - Overwrites the thousands delimiter.
  # :separator - Overwrites the separator between the units.
  #
  # ==== Examples
  # 12345678.with_delimiter      # => 12,345,678
  # 12345678.05.with_delimiter   # => 12,345,678.05
  # 12345678.with_delimiter(:FR) # => 12.345.678
  # 12345678.with_delimiter(:US) # => 12,345,678
  #
  #---
  # @public
  def with_delimiter(format_name = nil, options = {})
    Transformer.with_delimiter(self, format_name, options)
  end
  
  # Formats with a level of <tt>:precision</tt> (e.g., 112.32 has a precision of 2).
  # You can pass another format to use and even overwrite the format's options.
  #
  #
  # ==== Parameters
  # format_name<Symbol>:: name of the format to use
  # options<Hash>:: options which will overwrite the used format
  #
  # ==== Returns
  # String:: a string representing the delimited number
  #
  # ==== Options
  # :precision - Overwrites the level of precision
  # :separator - Overwrites the separator between the units
  # :delimiter - Overwrites the thousands delimiter
  #
  # ==== Examples
  # 111.2345.with_precision                       # => 111.235
  # 111.2345.with_precision(:UK, :precision => 1) # => "111.2"
  # 1234.567.with_precision(:US, :precision => 1, :separator => ',', :delimiter => '-') # => "1-234,6"
  #
  #---
  # @public
  def with_precision(format_name = nil, options = {})
    Transformer.with_precision(self, format_name, options)
  end
  
  # Formats into a currency string (e.g., $13.65). You can specify a format to use 
  # and even overwrite some of the format options.
  #
  # ==== Parameters
  # format_name<Symbol>:: name of the format to use
  # options<Hash>:: options which will overwrite the used format
  #
  # ==== Returns
  # String:: a string representing the number converted in currency
  #
  # ==== Options
  # :precision - Sets the level of precision 
  # :unit - Sets the denomination of the currency 
  # :format - Sets the format of the output string (defaults to "%u%n"). The field types are:
  #
  # %u The currency unit
  # %n The number
  #
  # ==== Examples
  # 1234567890.506.to_currency(:US)                   # => "$1,234,567,890.51"
  # 1234567890.506.to_currency(:US, :precision => 1)  # => "$1,234,567,890.5"
  # 1234567890.516.to_currency(:FR)                   # =>"1 234 567 890,52€"
  # 1234567890.516.to_currency(:US, :unit => "€")     # =>"€1,234,567,890.52"
  # 1234567890.506.to_currency(:US, :precision => 3, :unit => "€") # => "€1,234,567,890.506"
  # 1234567890.506.to_currency(:AU, :unit => "$AUD", :format => '%n %u') # => "1,234,567,890.51 $AUD"
  #---
  # @public
  def to_currency(format_name = nil, options = {})
    Transformer.to_currency(self, format_name, options)
  end

  # Formats a +number+ into a two digit string. Basically it prepends an integer to a 2 digits string.
  #
  # ==== Returns
  # String:: a string representing the number converted into a 2 digits string.
  #
  # ==== Examples
  # (5-3).two_digits # => "02"
  #
  #---
  # @public
  def two_digits
    Transformer.two_digits(self)
  end

  # Converts a +numeric+ value representing minutes into a string representing an hour value
  #
  # ==== Parameters
  # number<Numeric>:: Numeric value representing minutes to convert in hours
  #
  # ==== Returns
  # String:: a string representing the numeric value converted in hours
  #
  # ==== Examples
  # 315.minutes_to_hours => "05:15"
  #
  #---
  # @public
  def minutes_to_hours
    Transformer.minutes_to_hours(self)
  end
  
  
end